I have a method which returns pointer of one of three relative classes:
Base* Base::search_by_name(string name) { children_iterator = children.begin(); while (children_iterator != children.end()) { if (name == (*children_iterator)->getName()) { switch ((*children_iterator)->class_number) { case 1: return ((Derived*)*children_iterator); case 2: return ((Derived2*)*children_iterator); case 3: return ((Derived3*)*children_iterator); } And I need to create an object exactly of the class, which class` pointer method returns
bool Base::set_connection(int number, string& process_object) { typeid(root->search_by_name(process_object)) myobject; // Derived myobject, Derived2 myobject or Derived3 myobject if (myobject != NULL) { string signal = this->getName(); myobject->get_connection (number, signal); //each class has its own realisation of get_connection I tryed the line typeid(root->search_by_name(process_object)) myobject;But it`s obviously silly. Could you advise something?
voidpointer and later typecast it accordingly. Not a clean solution though.