1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
class MyClass
{
public:
MyClass(int x, int y, int z) : m_x(x), m_y(y), m_z(z)
{}
int m_x, m_y, m_z;
void set(int x, int y, int z)
{
m_x = x;
m_y = y;
m_z = z;
}
private:
};
int operator<(const MyClass &left, const MyClass &right)
{
return ((left.m_x < right.m_x) || (left.m_y < right.m_y) || (left.m_z < right.m_z));
}
void main()
{
int norm = 1, phi = 2, theta = 3;
int counter = 0;
std::map<MyClass, int> myClasses;
MyClass p(norm,phi,theta);
for (int k=0; k < 3; k++)
{
std::pair<std::map<MyClass, int>::iterator,bool> success;
success = myClasses.insert(std::pair<MyClass, int>(p,counter));
p.set(k + 10,k + 20,k + 30);
if (success.second)
{
counter++;
}
else
{
//std::cout << myClasses[p] << std::endl;
cout << "Exists" << endl;
}
}
std::map<MyClass, int>::iterator it;
for (it = myClasses.begin(); it!=myClasses.end(); it++)
{
std::cout << it->first.m_x << ", " << it->first.m_y << ", " << it->first.m_z << endl;
}
}
|