Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Function that returns a function pointer

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 James Leighe   Members   

222
Like
0Likes
Like

Posted 28 December 2011 - 12:01 PM

how do you implement a function that returns a function pointer without using typedefs that's also in a class? (in c++)

i'm pretty sure i can declare it like this
class Stupid
{
public:
  void (*GetFnValue( char* key ))( );
};

but i'm lost at implementation, something like
void (*fn)( )
Stupid::GetFnValue( char* key )
{
  return whatev;
}

tanks

#2 SiCrane   Moderators   

11761
Like
1Likes
Like

Posted 28 December 2011 - 12:06 PM

You could do:

void (*Stupid::GetFnValue( char* key ))()
{
  return 0;
}
but you should probably just typedef the function pointer.

#3 Misery   Members   

354
Like
1Likes
Like

Posted 28 December 2011 - 04:41 PM

If it is C++ maybe it is worth trying to use functor instead of function pointers.
class Stupid
{
public:
  void (*GetFnValue( char* key ))( );
};

The above code could be changed to:
class Stupid
{
public:
  MyFunctorClass FunRetFun(argtypes arguments)
};

and the latter part:
class MyFunctor{
   public:
   MyFunctor(char* key)
   {
	 //do some stuff
   }
}


and if You want a function returning a function it would just be sth like this:
MyFunctorClass Stupid::FunRetFun(argtypes arguments)
{
  //do something
return SomeInstance of MyFunctorClass;
}

I don't know if thats handy in Your application, but in a few programs that I have created it worked very well and it was much more comfy to use.
Regards




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.