I need a key in the map, however, I found it should be multiple data. Can I put these data in one user defined class and put the whole class as a key in the map?
Will it impact the time efficiency?
What other concerns should be applied here?
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.
Any type can be used as a key as long as it is
If your class is just a simple structure, then it’s already copyable and assignable. For a class to be comparable, you must either implement
operator<, or create the map with a custom comparison function to use instead.The only impact on time efficiency comes from larger objects taking longer to copy and compare. If the objects need to be that size, then there’s nothing you can do about that, so don’t worry about it.