Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

inheriting stl containers

This topic is 2582 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 want to add some functionality to the standard containers. The standard advice is to use free functions, but there are some things that can only be done with member functions (in this case I'm trying to add a const version of the map [] operator).

Normally, people warn about inheriting from containers due to the lack of virtual destructor. But this only seems like a problem if 1) The derived class has nontrivial destructor, 2)You heap allocate your container 3)You delete it through a pointer to base class. This isn't a likely occurrence.

Anyway, my main concern was whether there were any reasons to avoid inheritance besides the lack of virtual functions. I'm afraid there's some sort of template magic that will get messed up if I do.

Share this post


Link to post
Share on other sites
Advertisement
I can't think of any other problems than those you mentioned. 2) is only a problem if you do 3).

C++11 adds std::map::at with both const and non-const version. Can't you use that instead?

Share this post


Link to post
Share on other sites

C++11 adds std::map::at with both const and non-const version. Can't you use that instead?


None of the websites I've seen have ever mentioned it, but it appears to work. Do you know where I can find more information about it?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!