Jump to content
  • Advertisement

Archived

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

Glandalf

Multiple Classes under the same STL template

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using STL to make a link list, but I have 3 seperate classes I want on the list. I was wondering if there is a way to put them all on the same list without using void pointers.

Share this post


Link to post
Share on other sites
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!