class A {};
class B: A {};
struct C {};
struct D: C {};
int main(void) {
A *clA = new B(); //1
B *clB = new B(); //2
C *stC = new D(); //3
D *stD = new D(); //4
delete clA;
delete clB;
delete stC;
delete stD;
return 0;
}
The base (parent) data type, from which the new one should be inherited, has a private access modifier by default for the class, and a public one for the struct (section 11.2 on p. 181 of the "International standard ISO/IEC 14882" document).
Therefore, the A data type is used within the B data type, it is impossible to cast B data type to a private A data type.
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать