C++ help with STL and sets

DaNorthface

Senior member
May 20, 2004
343
0
0
Hi, i need some help working the STL set (sorted list). I'm trying to create a sorted list of objects, however, i'm not sure how to make the set know what data member to compare when sorting. I know i need something like set<Class_Name, compare> mySet; But i don't know how to implement 'compare' to make it compare the objects.

any help would be great. Thanks!
 

DaNorthface

Senior member
May 20, 2004
343
0
0
thanks for the quick reply. It works, but i'm getting some error messages in ms visual 6 c++ /w sp5. Any ideas? This is how i used the set:

struct Event
{
int time; // Time of the event
int transaction;
}; // End Event

// this is just the header of ltstr , the implementation returns a bool
struct ltstr {
bool operator() (const Event&amp; lhs, const Event&amp; rhs);
};

set<Event, ltstr> eventList;

warning messages are:

C:\Documents and Settings\BartonMXP\My Documents\Project3\Bank.cpp(22) : warning C4786: 'std::pair<std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::ite
rator,std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::iterator>' : identifier was truncated to '255' characters in the debug information

C:\Documents and Settings\BartonMXP\My Documents\Project3\Bank.cpp(22) : warning C4786: 'std::pair<std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::con
st_iterator,std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::const_iterator>' : identifier was truncated to '255' characters in the debug information

c:\program files\microsoft visual studio\vc98\include\xtree(160) : warning C4786: 'std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::_Tree<Bank::Event,B
ank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >' : identifier was truncated to '255' characters in the debug information

c:\program files\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std::pair<std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::iterator
,bool>::pair<std::_Tree<Bank::Event,Bank::Event,std::set<Bank::Event,Bank::ltstr,std::allocator<Bank::Event> >::_Kfn,Bank::ltstr,std::allocator<Bank::Event> >::iterator,bool>' : identifier was truncated to '255' characters in the debug information

Linking...


I also did it using the following:

struct Event
{
int time; // Time of the event
int transaction; // -1 is departure, >= 0 is transaction time of arrival

bool operator< (const Event&amp; a) const
{
return (time < a.time);
}

}; // End Event

but that had more warning messages. Any ideas?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
those are not errors and are expected when using STL in debug configuration in vc++ 6

you can disable it with a pragma directive if it gets really annoying
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
"Before .NET, Microsoft stated that what they are creating is "a Windows compiler." Their interest was in creating a compiler that makes Windows programs, and not one that is compliant to the C++ Standard. As a result, the Standard C++ features in pre-.NET VC++ increased at a relative crawl, and you should not expect that compiler to compile many of the programs in the book." -- http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html#Compilers

translated: vc++ 6 sucks, if you are programming in modern c++ style.