(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); [C++] public 상속 :: 깜냥깜냥

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<iostream>
#include<string>
#pragma warning(disable:4996)
using namespace std;
 
class A {
    int a1;
protected:
    int b1;
public:
    int c1;
    void setA1(int a1) {
        this->a1 = a1;
    }
    int getA1()const
    {
        return a1;
    }
    void setB1(int b1) {
        this->b1 = b1;
    }
    int getB1()const
    {
        return b1;
    }
    void setC1(int c1) {
        this->c1 = c1;
    }
    int getC1()const
    {
        return c1;
    }
};
class B : public A {
    int a2; ;
protected:
    int b2;
public:
    int c2;
    void setA2(int a2) {
        this->a2 = a2;
    }
    int getA2()const
    {
        return a2;
    }
    void setB2(int b2) {
        this->b2 = b2;
    }
    int getB2()const
    {
        return b2;
    }
    void setC2(int c2) {
        this->c2 = c2;
    }
    int getC2()const
    {
        return c2;
    }
};
 
class C : public B { 
    int a3; 
 
protected:
    int b3;
public:
    int c3;
    void setA3(int a3) {
        this->a3 = a3;
    }
    int getA3()const
    {
        return a3;
    }
    void setB3(int b3) {
        this->b3 = b3;
    }
    int getB3()const
    {
        return b3;
    }
    void setC3(int c3) {
        this->c3 = c3;
    }
    int getC3()const
    {
        return c3;
    }
};
 
void main() {
    C cc;
    cc.setA1(1);
    cc.setB1(2);
    cc.setC1(3);
    cc.setA2(4);
    cc.setB2(5);
    cc.setC2(6);
    cc.setA3(7);
    cc.setB3(8);
    cc.setC3(9);
 
    cout << cc.getA1() << "\t" << cc.getB1() << "\t" << cc.getC1() << "\t" << cc.getA2() << "\t"
        << cc.getB2() << "\t"<< cc.getC2() << "\t" << cc.getA3() << "\t" << cc.getB3() << "\t" << cc.getC3() << endl;
}
 


'code > C++' 카테고리의 다른 글

[c++] private 상속  (0) 2017.04.20
[C++] protected 상속  (0) 2017.04.20
[C++] 다중 상속  (0) 2017.04.20
[C++] 성적처리 동적리턴  (0) 2017.04.20
[C++] 성적관리-동적할당  (0) 2017.04.20

+ Recent posts