Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

행복한 개구리

C++ Classes - Inheritance / Multiple Inheritance 본문

C++/공부내용

C++ Classes - Inheritance / Multiple Inheritance

HappyFrog 2022. 6. 29. 18:44


 

 

 

다중 상속

또한 클래스는 하나 이상의 클래스를 쉼표로 구분한 목록으로 상속받을 수 있습니다.

 

 

예시

#include <iostream>

using namespace std;

// 기반 클래스
class MyClass {
public:
	void myFunction() {
		cout << "Some content in parent class.";
	}
};

// 또 다른 기반 클래스
class MyOtherClass {
public:
	void myOtherFunction() {
		cout << "Some content in another parent class";
	}
};

// 파생 클래스
class MyChild : public MyClass, public MyOtherClass {
};

int main() {
	MyChild myObj;
	myObj.myFunction();
	myObj.myOtherFunction();

	return 0;
}