C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

can't initialize static data member in triply-nested class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
grace petro
Guest





PostPosted: Fri Oct 29, 2004 1:43 am    Post subject: can't initialize static data member in triply-nested class Reply with 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!

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





PostPosted: Fri Oct 29, 2004 2:22 pm    Post subject: Re: can't initialize static data member in triply-nested cla Reply with quote



"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





PostPosted: Fri Oct 29, 2004 2:36 pm    Post subject: Re: can't initialize static data member in triply-nested cla Reply with quote



[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





PostPosted: Sun Oct 31, 2004 11:13 am    Post subject: Re: can't initialize static data member in triply-nested cla Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.