簡単な継承
- 11
- 20
- :
-
- |
- #include <iostream>
- using namespace std;
-
- class ClsA {
- public:
- void show() {
- cout << "this is A" << endl;
- }
- void doSthA() {
- cout << "do sth A" << endl;
- }
- };
-
- class ClsB : public ClsA {
- public:
- void show() {
- cout << "this is B" << endl;
- }
-
- void doSthB() {
- cout << "do sth B" << endl;
- }
- };
-
-
- int main() {
- ClsA a;
- ClsB b;
- a.show();
- a.doSthA();
- // a.doSthB(); , a doSthB
- b.show();
- b.doSthA();
- b.doSthB();
- }