FIX: No Error and Constructor Not Called if Prototype MissingLast reviewed: September 19, 1997Article ID: Q152055 |
The information in this article applies to:
SYMPTOMSIf a class declaration does not contain a default constructor declaration, but there is a definition of a default constructor, no error message is generated and the constructor is never called. The problem can be reproduced by building the sample code below.
RESOLUTIONMake sure that each constructor implementation has its prototype in the class declaration.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.
MORE INFORMATION
Sample Code
/* Compile options needed: none */ #include <iostream.h> class MyClass { public: int m_n; // No declaration of a default constructor }; MyClass::MyClass() : // C2600 here. m_n (42) { } void main() { MyClass t; // Default constructor is not called cout << "m_n is " << t.m_n << endl; cout << "It should be 42 "; cout << "if the correct default constructor was called." << endl; }Visual C++ 5.0 generates the following error when compiling the sample code above:
error C2600: 'MyClass::MyClass' : cannot define a compiler-generated special member function (must be declared in the class first) Keywords : CPPIss CPPLngIss vcbuglist400 vcfixlist500 Version : 4.0 4.1 4.2 Platform : NT WINDOWS Issue type : kbbug Solution Type : kbfix |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |