c++ - 返回值如果想要传值而不是传引用或指针是不是无法做到多态?
阿神
阿神 2017-04-17 13:32:37
0
3
578
阿神
阿神

闭关修行中......

reply all(3)
左手右手慢动作

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

洪涛

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"

迷茫

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;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template