ringa_lee2017-04-17 13:34:37
This seems to have little to do with polymorphism, mainly because you want it 实例化一个纯虚类,这是非法的
.
You have a A::foo()=0
indicating that A is a pure virtual class, but you also write A getA()
to return an object, that is, an instance of A. That obviously doesn’t work
PHP中文网2017-04-17 13:34:37
A is an abstract class and is not allowed to be instantiated. In other words, class A will not have objects. The getA() method in class B returns an object of A, which violates the principle of "not allowed to be instantiated"
迷茫2017-04-17 13:34:37
1 Abstract classes cannot be instantiated, so the compiler reports an error;
2 If you use objects instead of references or pointers, polymorphic effects cannot be achieved;