类继承,虚函数返回值

来源:互联网 发布:网络优化是什么意思 编辑:程序博客网 时间:2024/06/05 15:10

当基类和派生类返回值为各自的指针或者引用时,但不可以为本身类类型


 

#include <iostream>#include <string>class A{public:    virtual A&(A*) showSelf()=0;    virtual A showSelf()=0;//error};class B:public A{public:    B&(B*) showSelf()    {std::cout << "B" << std::endl;return *this;}    B showSelf()    {std::cout << "B" << std::endl;return *this;}//error};int main(void){    B b;    b.showSelf();    return 0;}