您的位置:首页 > 其它

不是通过引用或指针调用的话,无法产生多态的效果

2013-06-20 22:59 274 查看
#include "stdafx.h"

#include"iostream"

using namespace std;

 class A {

public :

    virtual void run (){cout<<"1"<<endl;}

};

class B :public A{

public:

    void run(){cout<<"2"<<endl;}

};

int f (A &pA){   // int f (A pA)

 //   pA->run();

  pA.run();

   return 0;

}

int main(int argc, char* argv[])



 A d;

 B b;

 int c=f(b);

 return 0;

}

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  多态 指针
相关文章推荐