Jump to content
  • Advertisement
Sign in to follow this  
kyok

STL multisets and classes

This topic is 5067 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 slowly learning more about STL and having a difficult time integrating a multiset into a class, the multiset is using my own data type. I'm not sure what simple mistake i'm making, but i can't use the .begin() or .end() on the multiset the way it currently is. This is the assumption my code is using: #include <set> #include <functional> struct DataType { int key; int key2; string value; }; bool less_than(DataType lhs, DataType rhs) { if(lhs.key < rhs.key) return true; if(lhs.key == rhs.key && lhs.key2 < rhs.key2) return true; return false; } typedef std::pointer_to_binary_function<DataType, DataType, bool> fn_type; typedef std::multiset<DataType, fn_type>::iterator multisetIter; class myClass { std::multiset<DataType, fn_type> testSet(fn_type(less_than)); public: multisetIter GetBegin() {return testSet.begin();} multisetIter GetEnd() {return testSet.end();} myClass() {} };

Share this post


Link to post
Share on other sites
Advertisement

std::multiset<DataType, fn_type> testSet(fn_type(less_than));

myClass() : testSet(fn_type(less_than)) {}


Member variable constructor parameters go into the class' constructor's initializer list.

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.

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!