|
-
September 8th, 2010, 04:59 PM
#1
Pointer to member function inheritance rules?
Hi everybody;
Member function pointer inheritance rules have been unclear to me, and several books that I have only make it muddier.
I tried last year to make a standard queue for processing function calls for my brood of objects. But I gave up when I found that that I could not use a base class function pointer an abstraction, although the signatures match for derived classes. This is a pretty simple illustration:
class AA {
public:
virtual int ff( const char* me ) { }
void assign( int (AA::*fPtr)(const char*) ) { }
};
class BB : public AA {
public:
int ff( const char* me ) { }
void assign( int (BB::*fPtr)(const char*) ) { }
};
int
main( int argc, char* argv[] )
{
AA a;
BB b;
a.assign( &AA::ff );
a.assign( &BB::ff );
return 0;
}
cc -o fp fp.cxx -lstdc++
fp.cxx: In function 'int main(int, char**)':
fp.cxx:33: error: no matching function for call to 'AA::assign(int (BB::*)(const char*))'
fp.cxx:12: note: candidates are: void AA::assign(int (AA::*)(const char*))
http://www.codeproject.com/KB/cpp/FastDelegate.aspx
says: "Member function pointers have a horrible restriction: they can only point to member functions of a single class."
This has been my experience. For racking and stacking various functions in an inheritance tree, pointers-to-member functions are pretty much useless. We were driven to use static functions for everything, esp. since static functions will inter-mingle with C functions. Our lib is very fast also. Given that I understand that member function pointers are often sizeof()x3 bigger than their static equivs and are hence non-interchangeable, I still want to know: Is this lack of inheritance in pointers-to-member-functions a religion thing (they are all the same size and lay out their args the same), or is there a technical reason that such a useful tool (IMHO is not allowed? Thanks ALOT...
me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|