Microsoft KB Archive/115521

= FIX: Private Copy Constructor Called Without Proper Access =

Article ID: 115521

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C/C++ Professional Development System 7.0
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 5.0 Learning Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Professional Edition
 * Microsoft Visual C++ 4.1 Subscription

-



This article was previously published under Q115521



SYMPTOMS
After declaring the only copy constructor in a class with an access of "private", the constructor is called when access should not be allowed. For example, when an instance of the class is passed as a parameter to a function, the copy constructor is used to initialize the parameter; this should be allowed only if the function has "private" access.



STATUS
Microsoft 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
The following sample code demonstrates this problem.

Sample Code
/* Compile options needed: none */

#include 

class aClass {     private: int i;         aClass(const aClass& x) { cout << "private copy constructor" << endl; };

public: aClass(int j) : i(j) {}; };

int func(aClass x) { return 0; };

int main(void) {         int n;          aClass a(1);

n = func(a); //Copy constructor gets called anyway.

return 0; }

Additional query words: kbVC400bug 8.00 8.00c 9.00

Keywords: kbbug kbfix kbvc500fix kbcpponly kbcompiler KB115521

-

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

© Microsoft Corporation. All rights reserved.