Archived

This topic is now archived and is closed to further replies.

member function pointers

This topic is 5506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


  
typedef bool (*Func)( void );

class myClass
{
private:
  Func _funcptr;
  bool function( void );

public
  myClass( void )
  {
    _funcptr = function;
  }
};
  
This generates an error: error C2440: ''='' : cannot convert from ''bool (__thiscall myClass::*)(void)'' to ''bool (__cdecl *)(void)'' There is no context in which this conversion is possible What is wrong and how do I fix it? I would prefferably like to do it in a ''clean'' matter, i.e. without global or friend functions or anything like it. -Luctus

Share this post


Link to post
Share on other sites
The problem is that you''re declaring _funcptr as a function pointer, when you really should be declaring it as a member function pointer (the two are not identical, since the latter takes an implicit argument "this" with the object, hence the "thiscall"). Take Kuphryn''s advice. Also read about member function pointers, because if you try to use them like regular function pointers you will run into a lot more problems.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Be careful, it''s a retarded badger, what ever that means

Share this post


Link to post
Share on other sites