多态,虚函数,指针

来源:转载

#include <iostream>
#include <vector>
using namespace std;

class A
{
public:

virtual void test( )
{
cout << "A" << endl;
}
private:
};

class B : public A
{
public:

void test( )
{
A::test( );
cout << "B" << endl;
}
private:
};

int main( )
{
vector <A*> v1;
B *b = new B( );
v1.push_back( b );
v1[0] -> test( );

cout << "------------------" << endl;

vector <A> v2;
B bb;
v2.push_back( bb );
v2[0].test( );
return 0;
}


分享给朋友:
您可能感兴趣的文章:
随机阅读: