How to call a parent class function from derived class function?

后端 未结 7 1099
自闭症患者
自闭症患者 2020-11-22 06:16

How do I call the parent function from a derived class using C++? For example, I have a class called parent, and a class called child which is deri

7条回答
  •  遥遥无期
    2020-11-22 06:56

    struct a{
     int x;
    
     struct son{
      a* _parent;
      void test(){
       _parent->x=1; //success
      }
     }_son;
    
     }_a;
    
    int main(){
     _a._son._parent=&_a;
     _a._son.test();
    }
    

    Reference example.

提交回复
热议问题