728x90
#include <iostream>

using namespace std;

class parents {
public:
	//자식 클래스의 멤버 함수
	void pFunc() 
	{
		cout << "부모클래스" << endl;
	}

	//자식 클래스의 멤버 변수
	int pnum;
};

class ch1: public parents {
public:
	//자식 클래스의 멤버 함수
	void ch1Func()
	{
		cout << "자식클래스" << endl;
	}

	//자식 클래스의 멤버 변수
	int ch1num;
};

int main() {

	//클래스를 인스턴스화 시킨다
	//클래스 구조를 메모리에 그대로 만든다
	//클래스명 > 객체명(변수명)

	parents p1;
	ch1 c1;

	p1.pnum = 1;

	p1.pFunc();


	c1.ch1num = 2;
	c1.ch1Func();
	
	c1.pnum = 3;

	cout << "부모 클래스의 변수 p1.pnum= " << p1.pnum << endl;
	cout << "자식 클래스의 변수 c1.ch1num= " << c1.ch1num << endl;
	cout << "자식 클래스에서 부모 변수 c1.pnum= " << c1.pnum << endl;
}
728x90

+ Recent posts