Answer the question
In order to leave comments, you need to log in
How to understand if a data type can be compared with each other?
I implement a dynamic array, hands reached sorting. How to understand whether it is generally possible to compare the data type that the user specified in the class template. It is clear that int and char are compared with each other, but what if the user passed some specific data type (for example, his own class)? How then to understand that this data type can be compared? Maybe he implements some kind of basic interface in C ++?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
If the user wants to use their class with your array, they will have to use the operator overloads (==, <, >) that you probably use when sorting. The fact is that they are not automatically determined for user classes (which is logical - the compiler cannot guess how to compare, for example, boxes - by volume or by weight).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question