https://reakwon.tistory.com/143
[C++] 클래스와 상속(Inheritance)의 개념과 사용법, 캡슐화의 이해
C++ 상속(Inheritance) 다른 여타의 객체지향언어와 같이 C++ 역시 상속을 할 수 있습니다. 여러분은 현실 생활에서 상속이라는 개념을 알고있으신가요? 부모님으로부터 100억을 상속을 받으셨다면 이
reakwon.tistory.com
상속 예제 (내 코드)
#include<iostream>
using namespace std;
struct item1 {
int a;
int b;
};
class parent {
public:
item1 A;
parent(int a, int b) {
this->A.a = a;
this->A.b = b;
}
void print() {
cout << this->A.a << endl;
cout << this->A.b << endl;
}
int c = 20;
};
class son : public parent {
public:
son(int a, int b):parent(a,b) {};
void show_info() {
print();
cout << c << endl;
}
void set() {
this->A.b = 21;
}
};
int main(void) {
son s(1,2);
s.print();
s.set();
s.print();
}
'C_C++' 카테고리의 다른 글
namespace 에 대해 (0) | 2022.12.05 |
---|---|
stringstream (0) | 2022.12.04 |
main( ) 매개변수 argc, argv 관련 (0) | 2022.09.29 |
한글 각각 출력하기 (0) | 2022.09.23 |
2차원 벡터 사용법 (0) | 2022.08.02 |