Hi everyone, been using this forum as a resource for quite awhile now. I have almost always been able to find a solution to my problems here
But i have a problem now i could really use some help with.
Say i have two classes defined something like this.
And i need to call a method that is declared like thisCode:class base //abstract { public: base() {}; virtual void foo() = 0; }; class top: public base { public: top() {}; virtual void foo() {} };
Supplying as argument, a list of top-objects ( and/or top-pointers )Code:void myFunc( std::list<base*>)
Code:std::list<top*> top_list; or std::list<top> top_list;
Example:
The reason i want myFunc to take a list of the base-class is that i need to call it with lists containing various classes derived from base.Code:void myFunc( std::list<base*> list ) { //yada yada } int main() { std::list<top> top_list; myFunc( <insert some sort of cast here? > top_list ); }
How can i possibly achieve this without redesigning myFunc( ) to take one single object/pointer?
Is it possible at all using the stl container classes?![]()



LinkBack URL
About LinkBacks



