1, 钻石型多重继承如果不想要底部的类有重复的变量,则需要声明为virtual继承

  class File{...};

  class InputFile: virtual public File{..};

  class OutputFile: virtual public File{....};

  class IOFile: public InputFile,

        public OutputFile

  {...};

2, 多重继承来的成员函数指向一边的指针不能访问另一边的函数

///////////////////////////////////////////////////////////////////////////////
//
// FileName : multi_inherit.h
// Version : 0.10 created 2013/11/08 00:00:00
// Author : Jimmy Han
// Comment :
//
///////////////////////////////////////////////////////////////////////////////
#ifndef MULTI_INHERIT_H
#define MULTI_INHERIT_H class base1{
public:
void baseFunc();
private:
int baseElem;
}; class derive1 : public base1 {
public:
void derive1Func();
private:
int derive1Elem;
}; class base2{
public:
void baseFunc();
private:
int baseElem;
}; class derive2 : public derive1, public base2{
public:
void derive2Func(); //to avoid ambigous
void baseFunc(); private:
int derive2Elem;
}; #endif
///////////////////////////////////////////////////////////////////////////////
//
// FileName : multi_inherit.cpp
// Version : 0.10
// Author : Ryan Han
// Date : 2013/07/26 16:50:14
// Comment :
//
///////////////////////////////////////////////////////////////////////////////
#include "multi_inherit.h" #include <iostream>
using namespace std; void base1::baseFunc() {
cout << "base1Func was called. " << endl;
} void base2::baseFunc() {
cout << "base2Func was called. " << endl;
} void derive1::derive1Func() {
cout << "derive1Func was called. " << endl;
} void derive2::derive2Func() {
cout << "derive2Func was called. " << endl;
} void derive2::baseFunc() {
base2::baseFunc();
}
///////////////////////////////////////////////////////////////////////////////
//
// FileName : multi_inherit_client.cpp
// Version : 0.10
// Author : Ryan Han
// Date : 2013/07/26 16:50:14
// Comment :
// Output :
// $ ./a
// $ ./a.exe
// base2Func was called.
// derive1Func was called.
// derive2Func was called.
// base1Func was called.
// derive1Func was called. ///////////////////////////////////////////////////////////////////////////////
#include "multi_inherit.h"
#include <iostream>
using namespace std; int main() {
derive2 d2;
//if not embed, this will be ambigous and compile error
d2.baseFunc();
//could call both derive1Func and derive2Func
d2.derive1Func();
d2.derive2Func(); derive1* b1 = new derive2;
//call base1 or derive1 functions, OK
b1->baseFunc();
b1->derive1Func();
//call base2 or derive2 functions, compile error.
//b1->derive2Func(); return ;
}

最新文章

  1. H5坦克大战之【玩家控制坦克移动2】
  2. Makefile 编写 tips
  3. 获取Finacial dimension value的description 值
  4. PHP与memcache安装使用说明
  5. C中文件操作说明
  6. chem02-- ajax登录
  7. JavaScript之图片轮换
  8. iOS开发——开发技巧&amp;Mac常用命令
  9. 【转】Java中本地时间的获取方法--不错
  10. java文件上传--基于ajaxFileUpload+struts2
  11. Express静态服务器
  12. Bypass_Disable_functions_Shell
  13. Poj3984 迷宫问题 (BFS + 路径还原)
  14. 《学习opencv》笔记——矩阵和图像操作——cvAnd、cvAndS、cvAvg and cvAvgSdv
  15. No identifier specified for entity: springboot-jpa报错No identifier specified for entity
  16. 使用easyui将json数据生成数据表格
  17. tmpx75 I2C 温度传感器驱动程序添加
  18. cocos2dx游戏--欢欢英雄传说--添加动作
  19. Laravel5.5 使用第三方Vendor添加注册验证码
  20. SQLAlchemy 简单笔记

热门文章

  1. (八)shell中的循环结构
  2. java获取客户访问IP
  3. windows服务名称不是单个单词的如何启动?
  4. Hibernate Projections(投影、统计、不重复结果)
  5. (转)TCP、UDP、IP协议
  6. jquery height
  7. EXEL表格读取 按键精灵
  8. 在centos6.5中安装jdk
  9. IoC 之 2.2 IoC 容器基本原理(贰)
  10. [saiku] 连接 mondrain 数据源出错-空指针错误