Multilevel Inheritance Trong C++

Multilevel Inheritance Trong C++
Rate this post

Multilevel Inheritance

Một lớp cũng có thể được dẫn xuất từ một lớp, lớp này đã được dẫn xuất từ một lớp khác.

Trong ví dụ sau, MyGrandChild có nguồn gốc từ lớp MyChild (có nguồn gốc từ MyClass).

Example

// Base class (parent)
class MyClass {
  public:
    void myFunction() {
      cout << "Some content in parent class." ;
    }
};

// Derived class (child)
class MyChild: public MyClass {
};

// Derived class (grandchild)
class MyGrandChild: public MyChild {
};

int main() {
  MyGrandChild myObj;
  myObj.myFunction();
  return 0;
}

 

0 / 5 - (0 Đánh Giá)

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com
.
.
.
.