更新时间:2022-11-03 21:17:26
这里根本没有继承.
您只是在创建class A
的对象作为class B
的成员变量.
这与在类内部或main
函数中的class B
对象中创建std::string
对象的方式相同.
因此,例如,您将无法执行任何多态性.A* ptr = new B;
将引发错误,因为这需要继承.
There is no inheritance here at all.
You''re simply creating an object ofclass A
as a member variable ofclass B
.
This is the same as how you created astd::string
object inside the class or an object ofclass B
in themain
function.
So, for example, you will not be able to perform any polymorphism.A* ptr = new B;
will throw an error because this needs inheritance.