64,676
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
using namespace std;
class Base
{
public:
Base(int a):Value(a){}
~Base(){};
int Value;
virtual void Print() const=0;
};
class B:public Base
{
public:
B(int a):Base(a){}
~B(){}
void Print()const {cout<<"B"<<" "<<Value<<endl;}
};
class A:public Base
{
public:
A(int a):Base(a){}
A(const B&b):Base(b.Value){}
~A(){}
void Print()const {cout<<"A"<<" "<<Value<<endl;}
};
void Test( const A &P)
{
P.Print();
cout<<P.Value;
}
int _tmain(int argc, _TCHAR* argv[])
{
A a(6);
B b(7);
Test(b);
return 0;
}