problem using function pointers

I

Irtech

Hello,

I have a class that has a function pointer member. for assigning functions to function pointer I use a public function "SetCallback".
at the construction time I want to assign a default function to my function pointer called "DefaultCallBack".
Unfortunately I couldn't do that till now because I get compiler errors.
I use VC++ in visual studio 2012 which supports c++11.

here is my code:
http://pastebin.com/CzxnnGPQ
Can you please tell me why this code does not compile ?
thanks.
 
R

red floyd

Hello,

I have a class that has a function pointer member. for assigning functions to function pointer I use a public function "SetCallback".
at the construction time I want to assign a default function to my function pointer called "DefaultCallBack".
Unfortunately I couldn't do that till now because I get compiler errors.
I use VC++ in visual studio 2012 which supports c++11.

here is my code:
http://pastebin.com/CzxnnGPQ

You have an error on line 42 of your code.
Seriously, though. Post the smallest *COMPILABLE* example here,
along with the specific error message you are getting.

We're not going to click on some random link.

See FAQ 5.8
 
W

Werner

Hello,



I have a class that has a function pointer member. for assigning functions to function pointer I use a public function "SetCallback".
I use VC++ in visual studio 2012 which supports c++11.



here is my code:
using std::function;
class command
{
function<void(enum_command_status)> m_callbackStatusChange;
void SetCallback(function<void (enum_command_status)> callbackNew
{m_callbackStatusChange = callbackNew;}
void DefaultCallBack(enum_command_status){delete this;}
}

Missing a ";" here above...
command::command()
{
SetCallback(DefaultCallBack);
}

What a surprise the user of this class will get...

int main()
{
command c;
c.SetCallback( xxx ); //Crash boom bang!
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top