Hey catfish2, thanks for your reply. How would I be able to use the setters/getters if I am using set? I am using vectors because of this.
I don't think std::set lets you modify objects after they're inserted. (For the reason that if you could do that, you'd mess up the order.)
So you can kiss your setters goodbye, but the getters will still work.
To iterate and display an std::set the old fashioned way, use:
for (std::set<Point>::const_iterator ci = mySet.begin(); ci != mySet.end(); ++ci)
std::cout << *ci << std::endl; // an iterator is a bit like a pointer
The new C++11 way (your compiler may not support this):
for (const Point &p: mySet) // range-based for loop
std::cout << p << std::endl;
Catfish2, is this the right way if I add one more int Z value in protected?
Not exactly. The purpose of a good operator< is to approximate Point1 < Point2 as well as possible.
So if you have x, y, z, it should look more like:
1 2 3 4 5 6 7 8 9 10 11 12
booloperator < (const Point &p) const
if (x == p.x)
if (y == p.y)
return z < p.z;
return y < p.y; // you miss this possibility
return x < px;