Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error C3754
Collapse the table of content
Expand the table of content

Compiler Error C3754

delegate constructor: member function 'function' cannot be called on an instance of type 'type'

A call was made to a function through a pointer to a type that does not contain the function.

The following sample generates C3754:

// C3754a.cpp
// compile with: /clr
using namespace System;

delegate void MyDel();

interface class MyInterface {};

ref struct MyClass : MyInterface {
   void f() {}
};

int main() {
   MyInterface^ p = gcnew MyClass;
   MyDel^ q = gcnew MyDel(p, &MyClass::f);   // C3754
   // try the following line instead
//   MyDel^ q = gcnew MyDel(safe_cast<MyClass^>(p), &MyClass::f);
}

The following sample generates C3754:

// C3754b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

__delegate void MyDel();

__gc __interface MyInterface {};

__gc struct MyClass : MyInterface {
   void f() {}
};

int main() {
   MyInterface* p = new MyClass;
   MyDel* q = new MyDel(p, &MyClass::f);   // C3754
   // try the following line instead
   // MyDel* q = new MyDel(__try_cast<MyClass*>(p), &MyClass::f);
}
Show:
© 2015 Microsoft