Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
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
Archives
Today
Total
관리 메뉴

행복한 개구리

C++ Classes - Inheritance / Multilevel Inheritance 본문

C++/공부내용

C++ Classes - Inheritance / Multilevel Inheritance

HappyFrog 2022. 6. 29. 18:39


 

 

 

다계층 상속

이미 파생된 클래스가 또 다른 클래스를 파생시킬 수 있습니다.

 

아래 예시에서  MyGrandChild 는  MyChild ( MyClass 로부터 파생된 클래스)로부터 파생된 클래스입니다.

 

 

예시

#include <iostream>

using namespace std;

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

// 파생 클래스 (자식)
class MyChild :public MyClass {
};

// 파생 클래스 (자식의 자식)
class MyGrandChild :public MyChild {
};


int main() {
	MyGrandChild myObj;
	myObj.myFunction();

	return 0;
}