Jump to content

  • Log In with Google      Sign In   
  • Create Account

Function that returns a function pointer


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   -  Reputation: 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

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9671

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   -  Reputation: 317

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.



PARTNERS