C++类的多继承:简单类型

1. 最简单的多继承

先对上面进行抽象

#include "stdio.h"
#include "iostream.h"
#include <string>
#if !define(AFX_123)

class CAAA
{
private:
int height;

public:
int GetHeight() const;
CAAA(int);

};
class CBBB
{
private:
char name;
public:
char GetName() const;
CBBB();
};
class CSon
{
private:
double classCdata;

public:
double GetClassCdata() cosnt;
CSon(int, char, double);
};


#define AFX_123
#endif

1.1对上述最简单的情况进行实现

#include "data.h"
//类AAA的实现
int CAAA::GetHeight() const
{
return height;
}

CAAA::CAAA(int height)
{
this->height=height;
}

//类BBB的实现
char CBBB::GetName() const
{
return name;
}
CBBB::CBBB(char name)
{
this->name=name;
}

//类CSon的实现
double CSon::GetClassCdata() const
{
return classCdata;
}
CSon::CSon(double classCdata)
{
this->classCdata=classCdata;
}

void main() { CAAA A(10); CBBB B('k'); CSon C(5,'a',2.5); }

1.2 不同基类的同名成员访问的二义性, 派生类对基类同名成员的覆盖性

 

 

posted @ 2013-01-05 09:53  血洗女生宿舍  阅读(156)  评论(0编辑  收藏  举报