| View previous topic :: View next topic |
| Author |
Message |
grace petro Guest
|
Posted: Fri Oct 29, 2004 1:43 am Post subject: can't initialize static data member in triply-nested class |
|
|
I'm getting a surprising compiler error when I try to initialize a
static data variable in a triply-nested class. I'm using Visual C++
6.
Am I doing something wrong here (other than by using Visual C++ 6)?
class A {
private:
class B {
private:
class C {
private:
};
static C *p2;
};
static B *p1;
};
A::B *A::p1; // ok
A::B::C *A::B::p2; // error!
The error is "cannot access private class declared in class 'A::B'".
I don't see why p1 should be ok, but p2 not. Any help would be
greatly appreciated!
Grace Petro
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Fri Oct 29, 2004 2:22 pm Post subject: Re: can't initialize static data member in triply-nested cla |
|
|
"grace petro" <victimofleisure2 (AT) yahoo (DOT) com> wrote...
| Quote: | I'm getting a surprising compiler error when I try to initialize a
static data variable in a triply-nested class. I'm using Visual C++
6.
Am I doing something wrong here (other than by using Visual C++ 6)?
class A {
private:
class B {
private:
class C {
private:
};
static C *p2;
};
static B *p1;
};
A::B *A::p1; // ok
A::B::C *A::B::p2; // error!
The error is "cannot access private class declared in class 'A::B'".
I don't see why p1 should be ok, but p2 not. Any help would be
greatly appreciated!
|
I am guessing, a compiler bug. The same code compiles fine with VC++ v7.1
V
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Serv? Laurijssen Guest
|
Posted: Fri Oct 29, 2004 2:36 pm Post subject: Re: can't initialize static data member in triply-nested cla |
|
|
[email]victimofleisure2 (AT) yahoo (DOT) com[/email] (grace petro) wrote in message news:<5afd59f.0410271730.2ff05fbd (AT) posting (DOT) google.com>...
| Quote: | Am I doing something wrong here (other than by using Visual C++ 6)?
class A {
private:
class B {
private:
class C {
private:
};
static C *p2;
};
static B *p1;
};
A::B *A::p1; // ok
A::B::C *A::B::p2; // error!
|
It works in C++Builder5 and I think it should.
You found a rather obscure bug in VC6
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Roger Orr Guest
|
Posted: Sun Oct 31, 2004 11:13 am Post subject: Re: can't initialize static data member in triply-nested cla |
|
|
"grace petro" <victimofleisure2 (AT) yahoo (DOT) com> wrote
| Quote: | I'm getting a surprising compiler error when I try to initialize a
static data variable in a triply-nested class. I'm using Visual C++
6.
Am I doing something wrong here (other than by using Visual C++ 6)?
class A {
private:
class B {
private:
class C {
private:
};
static C *p2;
};
static B *p1;
};
A::B *A::p1; // ok
A::B::C *A::B::p2; // error!
The error is "cannot access private class declared in class 'A::B'".
|
Microsoft VC6 had a number of problems with declarations involving private
classes/methods/etc.
These mostly seem to be resolved with VC 7 (and higher).
You could use the preprocessor to conditionally use public/private for the
nested class if you
wish to retain the intent of what you're doing for future migration to a
newer/different compiler
Roger Orr
--
MVP in C++ at www.brainbench.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|