Private inheritance vs internal class declaration

D

Dave Rahardja

MSVC seems to have a tough time with this program:


struct A
{
struct L
{};
};

struct B: private A::L
{
struct L
{};
};

struct C: public B::L // <-- Error: see below
{
};

int main()
{
C c;
}

---
error C2247: 'A::L' not accessible because 'B' uses 'private' to inherit from
'A::L'

It seems to me that A::L and B::L are completely different classes, and the
fact that B inherits privately from A::L should effectively hide the A::L
interface from B's users.

It also seems that MSVC is the only compiler complaining about this. Both g++
and Metrowerks CodeWarrior accept the code. Is this an MSVC bug, or am I
getting the standard mixed up?

-dr
 
M

Marcus Kwok

Dave Rahardja said:
MSVC seems to have a tough time with this program:


struct A
{
struct L
{};
};

struct B: private A::L
{
struct L
{};
};

struct C: public B::L // <-- Error: see below
{
};

int main()
{
C c;
}

---
error C2247: 'A::L' not accessible because 'B' uses 'private' to inherit from
'A::L'

It seems to me that A::L and B::L are completely different classes, and the
fact that B inherits privately from A::L should effectively hide the A::L
interface from B's users.

It also seems that MSVC is the only compiler complaining about this. Both g++
and Metrowerks CodeWarrior accept the code. Is this an MSVC bug, or am I
getting the standard mixed up?

It compiles with Comeau Online, so I am inclined to say it is an MSVC
bug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top