4 Jun 2003 23:00
pointer-to-member?
Andras Balogh <bnd <at> mailbox.hu>
2003-06-04 21:00:10 GMT
2003-06-04 21:00:10 GMT
Hi! Using C++, I'd like to call an object's member function without
knowing the type of the object. Of course the function type and a
pointer to the object is known. I mean I'd like to pass the function's
pointer somehow, so that another function can call it, using a pointer
to the object and the pointer to the member function. Is it possible
to do that? How?
I've been looking at pointer-to-member operators, but this seems to
require the type of the object (ie. the class). What is this
pointer-to-member stuff is good for anyway?? Every example code I see
does something like this:
class Base
{
public:
void Print() {printf("Test\n");}
};
void (Base ::* f)() = &Base :: Print;
void main()
{
Base *b = new Base;
(b->*f)();
}
This is all very nice, but what is the point? We know the type of the
object, why not simply use "b->Print();" instead???
Thanks,
(Continue reading)
Cheers,
/ h+
> -----Original Message-----
> From: sweng-gamedev-midnightryder.com-admin <at> lists.midnightryder.com
> [mailto:sweng-gamedev-midnightryder.com-admin <at> lists.midnightryder.com]On
> Behalf Of Andras Balogh
> Sent: Wednesday, June 04, 2003 2:00 PM
> To: sweng-gamedev <at> midnightryder.com
RSS Feed