rfg@paris.ics.uci.edu (Ronald Guilmette) (02/15/90)
// cfront 2.0 bug 900214_03 // cfront fails to allow pointers to members to be dereferenced without // prefix object specifications within member functions of the same class. // g++ allows this reasonable shorthand notation. struct struct0 { int data_member; void function_member (); }; int struct0::*dmp; int (struct0::*fmp) (); int i; void struct0::function_member () { i = (this->*fmp) (); i = this->*dmp; i = (*fmp) (); // gets bogus error i = *dmp; // gets bogus error } int main () { return 0; }
jeffa@hpmwtd.HP.COM (Jeff Aguilera) (02/16/90)
> i = (this->*fmp) (); From my cfront bug file: /* The rules for calling a pointer to a member function are given in the C++ Reference Manual: 5.5 Pointer-to-Member Operators The binary operator .* binds its second operand, which must be of type "pointer to member of class T" to its first operand, which must be of class T or of a class publicly derived from class T. The result is an object or a function of the type specified by the second operand. The binary operator ->* binds its second operand, which must be of type "pointer to member of T" to its first operand, which must be of "pointer to T" or "pointer to class publicly derived from T." The result is an object or a function of the type specified by the second operand. */ class X { public: X(); void (X::*PMF)(); void MF(); void okay(); void stillokay(); void wishlist(); }; void X::MF() {} X::X() { PMF = &X::MF; } void X::okay() { (this->*PMF)(); } void X::stillokay() { ((*this).*PMF)(); } //void X::wishlist() { (*PMF)(); } //(this-> must be explicit, unlike access to other members) //CC X.c: //"X.c", line 18: error: pointer to member de referenced //"X.c", line 18: error: object or pointer missing for ? of type void X::() //CC: 2 errors //void bad(X*const that) { (that->*PMF)(); } //CC X.c: //"X.c", line 25: error: PMF undefined //"X.c", line 25: error: pointer to member expected in .* expression: any //CC: 2 errors //void worse(X& self) { (self.*PMF)(); } //CC X.c: //"X.c", line 31: error: PMF undefined //"X.c", line 31: error: pointer to member expected in .* expression: any //CC: 2 errors