Archived

This topic is now archived and is closed to further replies.

Glandalf

Multiple Classes under the same STL template

Recommended Posts

Using inheritance and polymorphism, you could create a list of base-class pointers. This would look something like

class IBase
{
public:
virtual void function1() = 0;
virtual void function2() = 0;
};

class Implementation1 : public IBase
{
public
virtual void function1()
{
// do something
}

// etc.
};

class Implementation2 : public Ibase
// etc.

typedef std::list BaseList;
BaseList MyList;
MyList.push_back(new Implementation1(/* etc */));
MyList.push_back(new Implementation2(/* etc */));
This is assuming these three types are in some way related; if not, then there''s really no point in storing them in the same list.

Share this post


Link to post
Share on other sites