Skip to main content
added 90 characters in body
Source Link
Juraj
  • 18.2k
  • 4
  • 30
  • 49

Use virtual functions. On object of type Child, fnc2 defined in Parent will call fnc1 of derived class Child:

class Parent {
  public:

  virtual void fnc1() {
  }
  
  void fnc2 {
    ...
    fnc1();
    ...
  } 
}

class Child : public Parent {
public:
  virtual void fnc1() {
    ...
  }
}

fnc2 will call fnc1 of derived class:

class Parent {
  
  virtual void fnc1() {
  }
  
  void fnc2 {
    ...
    fnc1();
    ...
  } 
}

class Child : Parent {
  virtual void fnc1() {
  }
}

Use virtual functions. On object of type Child, fnc2 defined in Parent will call fnc1 of class Child:

class Parent {
public:

  virtual void fnc1() {
  }
  
  void fnc2 {
    ...
    fnc1();
    ...
  } 
}

class Child : public Parent {
public:
  virtual void fnc1() {
    ...
  }
}
Source Link
Juraj
  • 18.2k
  • 4
  • 30
  • 49

fnc2 will call fnc1 of derived class:

class Parent {
  
  virtual void fnc1() {
  }
  
  void fnc2 {
    ...
    fnc1();
    ...
  } 
}

class Child : Parent {
  virtual void fnc1() {
  }
}