47 lines
948 B
C++
47 lines
948 B
C++
#include <iostream>
|
|
|
|
class A {
|
|
protected:
|
|
int a;
|
|
public:
|
|
A() : a(1) {};
|
|
int get() { return a; }
|
|
int methodA() { return 100;}
|
|
};
|
|
|
|
class B : protected A {
|
|
//class B : private A {
|
|
protected:
|
|
int b;
|
|
public:
|
|
B() : A(), b(2) {};
|
|
int get() { return b+a; }
|
|
int methodB() { return methodA() + 200;}
|
|
};
|
|
|
|
class C : private B {
|
|
protected:
|
|
int c;
|
|
public:
|
|
C() : B(), c(3) {};
|
|
int get() { return c+b+a; }
|
|
//int get() { return c+b; }
|
|
int methodC() { return methodA() + 300;}
|
|
//int methodC() { return methodB() + 300;}
|
|
};
|
|
|
|
int main() {
|
|
A a;
|
|
B b;
|
|
C c;
|
|
std::cout << a.get() << std::endl;
|
|
std::cout << b.get() << std::endl;
|
|
std::cout << c.get() << std::endl;
|
|
std::cout << "------------" << std::endl;
|
|
std::cout << a.methodA() << std::endl;
|
|
std::cout << b.methodB() << std::endl;
|
|
std::cout << c.methodC() << std::endl;
|
|
return 0;
|
|
}
|
|
|