J
Jonathan Potter
Hi, I was wondering if someone could explain something to me.
We recently upgraded to a new C++ compiler and found some old code wouldn't
compile.
Boiled down, the code that causes the error is:
class A
{
};
class B : private A
{
};
class C : public B
{
public:
// error here
void Func(A& a);
}
The error from the compiler is "'A' not accessible because 'B' uses
'private' to inherit from 'A'"
When I contacted the vendor's support about this I got the response:
"This is the way C++ works. The use of private inheritance turns all
non-private members of the base class into private members of the derived
class, and disallows all standard conversions between derived to base . This
construction
void Func:A& a);
will work"
And he's right, it does work. I'm just wondering - what is the error in my
original construct? I can't see where the "conversion" that the response
refers to is. I'm not trying to convert anything from derived to base. I
simply have a function in the derived class to which I am passing a
parameter of the same type as the base class.
Thanks,
Jon
We recently upgraded to a new C++ compiler and found some old code wouldn't
compile.
Boiled down, the code that causes the error is:
class A
{
};
class B : private A
{
};
class C : public B
{
public:
// error here
void Func(A& a);
}
The error from the compiler is "'A' not accessible because 'B' uses
'private' to inherit from 'A'"
When I contacted the vendor's support about this I got the response:
"This is the way C++ works. The use of private inheritance turns all
non-private members of the base class into private members of the derived
class, and disallows all standard conversions between derived to base . This
construction
void Func:A& a);
will work"
And he's right, it does work. I'm just wondering - what is the error in my
original construct? I can't see where the "conversion" that the response
refers to is. I'm not trying to convert anything from derived to base. I
simply have a function in the derived class to which I am passing a
parameter of the same type as the base class.
Thanks,
Jon