Jump to content
  • Advertisement


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


Template problems

This topic is 5414 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

Lets say im making a vector list that contains vector lists. how do i make the vector list contain vector list of any type. vector> list; list.push_back(vector) list.push_back(vector) list.push_back(vector) like that. any help would be apreciated.

Share this post

Link to post
Share on other sites
There''s no good way to do that. About the best you can do is create a non-templated base class, and then create a templated class that inherits from the base class containing a vector of differing types in it. Then you can create a vector of pointers to that base class and add dynamically created members of the descendant template classes to the vector of pointers.

Share this post

Link to post
Share on other sites
You have to understand that the STL containers are homogeneous.
That means the items must be of the same type (or convertible
to it, such as derived-to-base pointers).

A vector < int > is a completely different type than vector < char >
and so on. They are not convertible.

For the same reason you can''t add ClassB object to vector < ClassA >, you can''t have what you want, at least not directly.

I think you need to ask yourself why you need scuh a list.
Maybe there''s another way to go about the problem you''re
trying to solve.

Kami no Itte ga ore ni zettai naru!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!