a vector of different class

hi
i have a base class and many other class that i have derived from this class
1
2
3
4
5
class Base{};
class Deri1: public Base{};// with private methode and attribut
class Deri2: public Base{};// with private methode and attribut
..
..

now i am parsing a buffer and so instanciate one of this class and stok it in a vector<Base*> myvector;
i relosve that with the cast
and after that, when i would like to do
myvector[i]->methodeofDeri1();//this methode is public
i will generate an error
error: class Base had no member call methodeofDeri1();

what can i do to resolve this problem?

thinks,
Last edited on
Put a virtual method in Base class called methodeofDeri1, then override it in the derived classes
so,
i have many derived class with many methodes that i can't put them as virtual in the base class!
so,
i have many derived class with many methodes that i can't put them as virtual in the base class!
Virtual functions are definately the way to go when you can. If that's not an option you can fall back to dynamic_cast

see second half of my post here (2nd post in the thread):

http://cplusplus.com/forum/windows/9891/
Topic archived. No new replies allowed.