容器不支持混合类型, 如果直接把派生类对象, 存入基类容器中, 则无法使用派生-基转换(derived-base conversion); 因为转换只能发生在指针和引用 过程中, 不能发生在 对象直接赋值, 如果是直接转换, 则会产生截断(sliced down); 即派生类部分被...
基于4个网页-相关网页
从基类到派生类的自动转换是不存在的。
There is no automatic conversion from the base class to a derived class.
当具有基类的引用或指针,但需要执行不是基类组成部分的派生类操作的时候,需要动态的强制类型转换。
Dynamic casts are needed when we have a reference or pointer to a base class but need to perform operations from the derived class that are not part of the base class.
应用推荐