Re: Class methods changed from pointer (VS6) to reference (VS7)
John Keenan <john.removeme.keenan@optimapowerware.com> wrote:
MyClass y;
invokeMethod( y, MyClass::myMethod ); // VS6
invokeMethod( y, &MyClass::myMethod ); // VS7 Note addition of &
The former was never a valid syntax, according to the C++ standard. VC6
supported it by analogy with regular functions, where a function name is
implicitly converted to a pointer-to-function:
void f();
typedef void (*PF)();
// These two declarations have the same meaning
PF pf = f;
PF pf = &f;
However, for non-static member functions, MyClass::myMethod is not a
syntactically valid expression. Not being a valid expression, it doesn't
have any type. In fact, there ain't no such thing as a
reference-to-member-function type anyway (but there is
pointer-to-member-function):
typedef const double (MyClass::*PtoM)() const; // OK
typedef const double (MyClass::&RtoM)() const; // not a valid syntax
PtoM = MyClass::myMethod; // invalid syntax, but VC6 supports it
PtoM = &MyClass::myMethod; // valid
VC7 tightened up standards conformance, and now errors on non-standard
syntax that VC6 allowed.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925