Microsoft KB Archive/255528

= BUG: Access Violation in Constructor with Variable Number of Arguments =

PSS ID Number: 255528

Article Last Modified on 10/16/2002

-

The information in this article applies to:


 * Microsoft C/C++ Compiler (CL.EXE)

-



This article was previously published under Q255528



SYMPTOMS
An access violation may occur if you have a class derived from ostringstream and if this class has a constructor with variable number of arguments.



CAUSE
Incorrect code is generated when the first argument in the variable argument list is a zero.



RESOLUTION
To workaround the problem, use any one of the following three resolutions:


 * 1) Do not use variable number of arguments for the class constructor.
 * 2) Let the first argument in the constructor's variable argument list be a non-zero value.
 * 3) Use a default class constructor with no arguments and then call another member function with a variable argument list.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
Compile Options : cl /GX test.cpp

//Test.cpp

using namespace std;
 * 1) include
 * 2) include

class Test : public ostringstream { public: Test(bool n, ...) {   } };

void main {       cout << "Calling Test " << endl; Test my_test1(true, 1); //OK.

cout << "Calling Test again " << endl; Test my_test2(true, 0); //Causes Access Violation

}

Keywords: kbBug kbCPPonly kbSTL KB255528

Technology: kbAudDeveloper kbCVCComp kbVCsearch

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.