c++/5551: g++ 3.0.3 friends and nested classes: fail to compile
Konstantin Osipov
rabid@ringrows.ru
Thu Jan 31 06:31:00 GMT 2002
>Number: 5551
>Category: c++
>Synopsis: nested classess, private constructors, and friends: fail to compile
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Thu Jan 31 03:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Konstantin Osipov
>Release: 3.0.3
>Organization:
>Environment:
glibc 2.2.4, Suse Linux 7.2
System: Linux rabid 2.4.16 #1 Thu Jan 3 22:52:25 MSK 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure
>Description:
Here is the source:
--cut
class Info
{
friend class Creator;
Info();
struct InfoRep;
InfoRep *_rep;
};
struct Info::InfoRep
{
char _data[16];
};
Info::Info()
:_rep(new InfoRep) {}
class Outer
{
friend class Creator;
Outer(Info *info);
struct OuterRep;
OuterRep *_rep;
};
struct Outer::OuterRep
{
Info* _info;
OuterRep(Info *info);
};
Outer::OuterRep::OuterRep(Info *info)
:_info(info) {}
Outer::Outer(Info *info)
:_rep(new OuterRep(info)) {}
class Creator
{
public:
Creator();
};
Creator::Creator()
{
Info info;
Outer outer(&info);
}
int main(int argc, char *argv[])
{
Creator c;
}
--cut
Here is the compiler outputd@rabid:/home/rabid> g++ test.cc
test.cc:10: `struct Info::InfoRep' is private
test.cc:22: within this context
rabid@rabid:/home/rabid>
>How-To-Repeat:
compile it.
>Fix:
If I move line 'friend class Creator;' in class Outer after the declaration
of struct OuterRep everything compiles OK:
--cut
class Outer
{
Outer(Info *info);
struct OuterRep;
OuterRep *_rep;
friend class Creator;
};
--cut
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list