Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   problem using function pointers (http://www.velocityreviews.com/forums/t954057-problem-using-function-pointers.html)

Irtech 10-30-2012 07:40 PM

problem using function pointers
 
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.

red floyd 10-30-2012 08:22 PM

Re: problem using function pointers
 
On 10/30/2012 12:40 PM, Irtech wrote:
> 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



Werner 10-31-2012 07:34 AM

Re: problem using function pointers
 
On Tuesday, October 30, 2012 9:40:28 PM UTC+2, Irtech wrote:
> 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!
}


All times are GMT. The time now is 04:43 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.