It is necessary to call the ob2 object method from the ex1 method of the ob1 object, using the link located in the ob1 object vector

class cl_1 { vector <cl_1 *> children; } class cl_2 : public cl_1 { void exe() { ///// } } class cl_3 : public cl_1 { void message() { std::cout <<"Massage"; } } int main() { cl_2 ob1; cl_3 ob2; ob1.children.push_back(&ob2); ob1.exe(); } 
  • ((cl_3 *)children[0])->message(); - Do you make a program for a massage room? - Igor
  • It makes sense to make the message method virtual. - VTT
  • one
    void exe () {((cl_3 *) children [0]) -> message (); } Should it be like that? - WoWkiller 11
  • Better this way: static_cast<cl_3 *>(children[0])->message(); . - HolyBlackCat
  • thanks, everything is clear - WoWkiller 11

0