一つの継承と多態についてのテーマ

1289 ワード

#include<iostream>
#include <complex>

using namespace std;
//----------------------------------------------
class Base// 
{
public:
	virtual void f(int);
	virtual void f(double);
	virtual void g(int i=10);
};

void Base::f(int)
{
	cout<<"Base::f(int)"<<endl;
}

void Base::f(double)
{
	cout<<"Base::f(double)"<<endl;
}

void Base::g(int i)
{
	cout<<i<<endl;
}
//------------------------------------------------

class Dervived:public Base
{
public:
	void f(complex<double>);
	void g(int i=20);
};

void Dervived::f(complex<double>)
{
	cout<<"Dervived::f(complex<double>)"<<endl;
}

void Dervived::g(int i)
{
	cout<<i<<endl;
}
//----------------------------------------------
void main()
{
	Base b;
	Dervived d;
	Base *pb=new Dervived; 
	b.f(1.0);// , 
	d.f(1.0);// , 
	pb->f(1.0);// , , , 
	b.g();// , 
	d.g();// , 
	pb->g();// , , , 
	delete pb;
}