Compiler Warning (level 4) C4256

'function' : constructor for class with virtual bases has '...'; calls may not be compatible with older versions of Visual C++

Possible incompatibility.

Based on the code sample below, if the definition of the constructor S2::S2( int i, ... ) was compiled with a version of Visual C++ prior to 7, but the code snippet here were compiled with current version, the call to the constructor for S3 would not work correctly, due to a special-case calling convention change. Note that if both were compiled with Visual C++ 6.0, the call would not work quite right either, unless no parameters were passed for the ellipsis.

To fix this warning,

  1. Don't use ellipsis in a constructor.

  2. Make sure that all components in their project are built with the current version (including any libraries that may define or reference this class), then disable the warning using the warning pragma.

The following sample generates C4256:

// C4256.cpp
// compile with: /W4
// #pragma warning(disable : 4256)
struct S1
{
};

struct S2: virtual public S1
{
   S2( int i, ... )    // C4256
   {
      i = 0;
   }
   /*
   // try the following line instead
   S2( int i)
   {
      i = 0;
   }
   */
};

void func1()
{
   S2 S3( 2, 1, 2 );   // C4256
   // try the following line instead
   // S2 S3( 2 );
}

int main()
{
}