ev@chorus.fr (Eric Valette) (03/26/90)
/* * Pointer to member and pointer to "normal" function : * C++ 2.0 should check the consistency of what is allowed and what * is not !! * * * The following program was written on sun3/80 (sunOS4.0) using the * Sun C++ 2.0 compiler */ class A { public: int i; A() {} int func(int a) { this->i = a; return a;} }; typedef int (A::*ptMemberA) (int); typedef int (*ptFuncValid) (A*,int); typedef int (*badPtFuncType) (int); A a; main() { ptMemberA pFunc1 = &A::func; ptFuncValid pFunc2 = (ptFuncValid) &A::func; /* line 30 */ ptFuncValid pFunc3 = (ptFuncValid) pFunc1; // produce a compiler error(see below) // What's the difference between // this line and the previous one !!! // (works with glockenSpiel prepocessor release 1.2 d) // I think it is a bug !!! // ----------------------- // Now look at the following line witch is syntacticaly correct // but do not produce what is expected ptFuncValid pFunc4 = (* ((ptFuncValid*) &pFunc1)) ; // Yet another possible bug badPtFuncType pFunc5 = (badPtFuncType) &A::func; // The compiler should be able to detect that the first // parameter expected by *pfunc5 is not a pointer to an object // of class A (and also be able to produce at least a warning // if it is not the case) // Now have a look at functions calls ((&a)->*pFunc1) (1); // works (*pFunc2) (&a,1); // correct /* line 57 */ (*pFunc4) (&a,1); // should do the same thing // in fact produces a bus error at run time !! // works with release 1.2d of glockenSpiel. //------------------------------------------- // (*pFunc1)(1); this line is (of course) not correct but // would have exactly the same effect as the // next one : (*pFunc5) (1); //is correct but produces a bug at run-time // (the value of this is 1 in the func // member function.) } /*-------------------Cut here-----------------------------------------------*/ /* if you compile this program using the following command : CC -o pfunc pfunc.cxx it produces : CC pfunc.cxx: "pfunc.cxx", line 30: sorry, not implemented: pointer to member of not first base 1 error (trying to understain the error message is hard, isn't it) if you remove line 30, it compiles but produces a bus error due to line 57. ============================================================================ I'll like to know how I can write something correct whitch would have the same effect as the line 30 in the previous version of C++ (1.2 [a-e]) . =========================================================================== thanks, __ / ` Eric Valette /-- __ o _. Chorus Systemes (___, / (_(_(__ 6 avenue Gustave Eiffel F-78182, St-Quentin-en-Yvelines-Cedex Tel: +33 (1) 30 57 00 22 Fax: +33 (1) 30 57 00 66 E-mail: ev@chorus.fr or ev%chorus.fr@mcsun.EU.net */