Compiler Error C2276
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Error C2276.
operator' : illegal operation on bound member function expression
The compiler found a problem with the syntax to create a pointer-to-member.
The following sample generates C2276:
// C2276.cpp
class A {
public:
int func(){return 0;}
} a;
int (*pf)() = &a.func; // C2276
// try the following line instead
// int (A::*pf3)() = &A::func;
class B {
public:
void mf() {
&this -> mf; // C2276
// try the following line instead
// &B::mf;
}
};
int main() {
A a;
&a.func; // C2276
// try the following line instead
// &A::func;
}
Show: