Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!think!mintaka!bloom-beacon!eru!luth!sunic!ericom!erix.ericsson.se!euas10c19.ericsson.se!euaeny From: euaeny@euas10c19.ericsson.se (Erik Nyquist) Newsgroups: comp.lang.c++ Subject: Pointer to member function - Bug??? Message-ID: <2580@erix.ericsson.se> Date: 28 Dec 89 15:34:48 GMT Sender: news@erix.ericsson.se Reply-To: euaeny@euas18.ericsson.se (Erik Nyquist) Organization: Ellemtel Utvecklings AB, Stockholm, Sweden Lines: 51 According to "C++ - Reference Manual", page 26: "A pointer to a member of class B may be assigned to a pointer to a member of class D of the same type provided D is derived from B (directly or indirectly) by public derivation." I wanted to try this with the program below. The Sun C++-compiler gives the following error message: CC +g pointer-to-member.C: "pointer-to-member.C", line 30: error: bad assignment type: void (B::*)(char *) = void (D::*)(char *) */ Why isn't the program accepted? //------------------------------ #include #define NL <<"\n" class B { public: B(){} void b_method(char* cp) { cout << "Base: " << cp NL; } }; class D : public B { public: D(){} void d_method(char* cp) { cout << "Derived:" << cp NL; } }; main(){ D d; void (B::*bfunction)(char*) = B::b_method; (d.*bfunction)("Hallo, World!"); bfunction = D::d_method; (d.*bfunction)("Goodbye, World!"); } ----------------------------------------------------------- Erik Nyquist Tel: +46 - 8 719 9603 Ellemtel Utvecklings AB email: euaeny@euas18.ericsson.se Box 1505 S- 125 25 Stockholm Sweden ===========================================================