private inheritance and public members

  • Thread starter Stéphane Ninin
  • Start date
S

Stéphane Ninin

Hello,

I have this piece of code:

class A {
public:
virtual void test(const A*);
};

class B : private A {
public:
virtual void test(const A*);
};

class C : B {
public:
virtual void test(const A*);
};


Depending on the compiler I use, code compiles fine or
compiler tells me:
test.cpp:1: error: `class A' is inaccessible
test.cpp:14: error: within this context

I guess the code is incorrect, but am not completely sure.

Any ideas / comments on this ?


Thanks.
 
V

Victor Bazarov

Stéphane Ninin said:
I have this piece of code:

class A {
public:
virtual void test(const A*);
};

class B : private A {
public:
virtual void test(const A*);
};

class C : B {
public:
virtual void test(const A*);

Write it as

virtual void test(const ::A*);
};


Depending on the compiler I use, code compiles fine or
compiler tells me:
test.cpp:1: error: `class A' is inaccessible
test.cpp:14: error: within this context

I guess the code is incorrect, but am not completely sure.

Any ideas / comments on this ?

Well, name lookup is a funky thing. Some find 'A' in the
namespace, some find it in the B (as B::A). The compilers that
don't complain are probably in error. IOW, they all _should_
complain.

V
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top