Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
'member' : cannot take the address of a non-static data member or method of a managed or WinRT type
An instance is needed to take the address of nonstatic data members of a managed or WinRT class or interface.
The following sample generates C2843 and shows how to fix it:
// C2843_2.cpp
// compile with: /clr
public ref class C {
public:
int m_i;
};
ref struct MyStruct {
static void sf() {}
void f() {}
};
int main() {
MyStruct ^ps = gcnew MyStruct;
void (__clrcall MyStruct::*F1)() = & MyStruct::f; // C2843
void (__clrcall MyStruct::*F2)() = & ps->f; // C2843
void (__clrcall MyStruct::*F3)(); // C2843
void (__clrcall *F5)() = MyStruct::sf; // OK
void (__clrcall *F6)() = & ps->sf; // OK
interior_ptr<int> i = &C::m_i; // C2843
C ^x = gcnew C();
interior_ptr<int> ii = &x->m_i;
}
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in