error C2248 - bug in MSVC71

  • Thread starter Thread starter Bronek Kozicki
  • Start date Start date
B

Bronek Kozicki

I've received following code snipped from some mailing list:

1 class A
2 {
3 private:
4 A();
5 protected:
6 A(int x) {}
7 public:
8 virtual ~A() {}
9 };
10
11 class B : virtual public A
12 {
13 protected:
14 B() : A(10) {}
15 public:
16 virtual ~B() {}
17 };
18
19 class C : public B
20 {
21 public:
22 C() : A(8) {}
23 };
24
25 int main(int argc, char* argv[])
26 {
27 C c1;
28 C c2 = c1; // error here
29 return 0;
30 }

MSVC71 fails to compile it (tried with and without option /Za) :
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

T91.cpp(28) : error C2248: 'A::A' : cannot access private member
declared in class 'A'
T91.cpp(4) : see declaration of 'A::A'
T91.cpp(2) : see declaration of 'A'

the same problem is exposed by newer MSVC compiler (DDK for AMD64):
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.2207 for AMD64

As far as I can understand C++ standard, there is no problem with
source. Line 28 is copy-initialization, compiler should have used
implicit non-trivial copy-constructor generated for C. Virtual base
subobject (A inside C) should have been copied by implicit-defined copy
constructor. Compiler is free to generate one for A; instead it tries to
use private default constructor for A. What's up?


B.

PS. other compilers (notably Comeau) accept this code.
 
Hello Bronek,

Thanks a lot for your feedback. This issue has been entered into our bug
database and it is being investigated. It is possible that this may be
resolved in the next Visual C++ compiler service pack, but I cannot
guarantee a resolution of this issue at this time. To work around this
problem, I suggest that you can declare A(); as a public or protected
member:

class A
{
// private:
protected: //or public:
A();
......
}

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top