Why last cicle in main
doesn't print all map?
#include <map>
#include <iostream>
using namespace std;
class NAME
{
private:
string name;
public:
NAME(string name)
{
this->name = name;
}
string getName() const
{
return name;
}
friend bool operator< (const NAME& n1, const NAME& n2);
};
bool operator< (const NAME& n1, const NAME& n2)
{
return false;
// return n1.getName() < n2.getName();
}
int main()
{
map <NAME, int> telephoneBook = { {NAME("Alex"), 1122},
{NAME("Oleg"), 3344},
{NAME("Den"), 5566} };
for (auto it = telephoneBook.begin(); it != telephoneBook.end(); ++it)
{
cout << (it->first).getName(); // prints only Alex
}
}
Output: Alex