Casting std::lists by value type
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.
Code:
class base //abstract
{
public:
base() {};
virtual void foo() = 0;
};
class top: public base
{
public:
top() {};
virtual void foo() {}
};
And i need to call a method that is declared like this
Code:
void myFunc( std::list<base*>)
Supplying as argument, a list of top-objects ( and/or top-pointers )
Code:
std::list<top*> top_list;
or
std::list<top> top_list;
Example:
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 );
}
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.
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? :confused: