Can I pass a child class to a reference of a parent class?
- by michael
Hi,
I have a class A which takes a reference of B in its constructor.
class A {
public:
A(B& b);
}
And I have a class SubB which is a child class of B:
class SubB : public B {
//omitted...
}
In my code, I create a SubB and pass it to A:
SubB subB;
A a(subB);
But I get this compile Error:
error: ‘B’ is an inaccessible base of ‘SubB’
Can I pass a reference of SubB as B?
Thank you.