Compiler says
ERROR1: the object has type qualifiers that are not compatible with the member function "NAME::getName" object type is : const NAME
ERROR2: 'std::string NAME::getName(void)': cannot convert 'this' pointer from '_Ty1' to 'NAME &'
on cout << (it->first).getName();
So why is that and how to make it work?
#include <map>
#include <iostream>
using namespace std;
class NAME
{
private:
string name;
public:
NAME(string name)
{
this->name = name;
}
string getName()
{
return name;
}
};
int main()
{
map <NAME, int> telephoneBook = { {NAME("Alex"), 1122},
{NAME("Oleg"), 3344} };
for (auto it = telephoneBook.begin(); it != telephoneBook.end(); ++it)///вывод на экран
{
cout << (it->first).getName(); // error 1 and error2
}
}