Topic: Alternative to "void* pAnyObject" wanted!
Author: hugp@actrix.gen.nz (Peter Hug)
Date: Fri, 20 May 1994 02:40:59 GMT Raw View
I posted article 7598 to this forum in the hope some specialist out there
could come up with the mother of all solutions to my problem. The problem
was that I found it extremely difficult to implement code which would
invoke a method on an abitrary object (i.e. all I have is a void* to an
object who's class is not known and the address of one of the objects NON-
static member-functions).
Since I got no perfect solution to my problem, I would like you C++ experts
to comment on the following C++ language extension: Implement a keyword
that can be used to reference any C++ class (I used CPPCLASS as the key-
word in the following sample code):
#include <iostream.h>
class A {
void cb () { cout << "A::cb()" << endl; }
}
class B {
CPPCLASS * px; // px is a pointer to an object who's class is unknown
void (CPPCLASS::*pfnx)(void); // pfnx is one of px's memberfuncs
B(CPPCLASS * p, void (CPPCLASS::*pfn)(void)) : px(p), pfnx(pfn) {};
void Notify () { px->(*pfnx)(); };
}
int main () {
A a;
B b(&a, &A::cbh);
b.Notify(); // should invoke a.cb()
return 0;
}
Cheers
--
Peter Hug | | Lieber
Maxi Solutions Ltd | Voice: (+64) 4 298 3441 | arm dran
Paraparaumu Beach | Fax: (+64) 4 297 2288 | als
New Zealand | email: hugp@actrix.gen.nz | arm ab