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

  1. 最简单的多继承

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

先对上面进行抽象

#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 不同基类的同名成员访问的二义性, 派生类对基类同名成员的覆盖性

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

原文链接: https://www.cnblogs.com/girlblooding/archive/2013/01/05/2845236.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/74559

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午4:28
下一篇 2023年2月9日 下午4:28

相关推荐