323k13l
asked on
C++ Sets and Their Types
I am new to C++, and I am writing a breath first search. I would like to use a set to prevent from adding elements to a data structure that are already contained in that data structure. Thus I know a set is what I want. But besides that I understand sets in C++ yet.
I am having trouble figuring out what types a set can take on. Assume set is included as well as Vertex.h...
std::set<int> mySet;
mySet.insert(10);
// This works!
std::set<Vertex> mySet;
Vertex v;
mySet.insert(v);
// This Doesn't Work!
Can sets only take on primitive data types. Can you make a set hold an object type other than primitive objects?
I am having trouble figuring out what types a set can take on. Assume set is included as well as Vertex.h...
std::set<int> mySet;
mySet.insert(10);
// This works!
std::set<Vertex> mySet;
Vertex v;
mySet.insert(v);
// This Doesn't Work!
Can sets only take on primitive data types. Can you make a set hold an object type other than primitive objects?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Nevermind, the only reason the above code did not work was because I left off the semicolon at the end of the declaration in the first code segment. Thank you for your help, Ichijo.
ASKER
bool operator<(const Vertex& right) const
In the source file I put:
bool operator<(const Vertex& right) const {
return ._name < right._name; // _name is a int class-variable
}
What am I doing wrong here?