Compiler Warning (level 1) C4358
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

Compiler Warning (level 1) C4358

Error Message

'operator': return type of combined delegates is not 'void'; returned value is undefined

Two delegates were combined and the return value is not void. If two delegates with non-void return values are combined, the compiler will not be able to do a proper assignment if the return value of the delegate is used.

The following sample generates C4358:

// C4358.cpp
// compile with: /clr /W1
delegate int D();
delegate void E();

ref class X {
   int i;
   X(int ii) : i(ii) {}
   int f() {
      return i;

ref class Y {
   int i;
   Y() {}
   void g() {}

int main() {
   D^ d = gcnew D(gcnew X(1), &X::f);
   D^ d2 = gcnew D(gcnew X(2), &X::f);

   d += d2;   // C4358
   int j = d();   // return value indeterminate

   E^ e = gcnew E(gcnew Y, &Y::g);
   E^ e2 = gcnew E(gcnew Y, &Y::g);
   e += e2;   // OK
© 2016 Microsoft