「C++」多重継承を利用するサンプル
書式
class クラス : public クラスA, public クラスB
使用例
#include <iostream>
using namespace std;
//クラスを定義
class TestA
{
public:
void getFuncA();
};
class TestB
{
public:
void getFuncB();
};
class TestC : public TestA, public TestB
{
public:
void getFuncC();
};
//メンバ関数の実装
void TestA::getFuncA()
{
cout << "AAA 111\n";
return;
}
void TestB::getFuncB()
{
cout << "BBB 222\n";
return;
}
void TestC::getFuncC()
{
cout << "CCC 333\n";
return;
}
//クラスを使用
int main() {
TestC tc;
tc.getFuncA();
tc.getFuncB();
tc.getFuncC();
return 0;
}
実行結果
AAA 111
BBB 222
CCC 333