Could a variable of Data be used as a map key?
struct Data {
Data(int X, int Y) {x=X; y=Y;}
int x; int y;
}
int main()
{
std::map<Data, int> map_;
map_.insert(std::make_pair(Data(1,2), 0)); //error inserting
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, but you either need to define
operator<for the class type or use a custom comparison function for thestd::map.There is an example of using a custom comparison function in the STL documentation.