I have the following code
#include <iostream>
#include <string>
class A : public std::string {
public:
A(int){};
};
int main() {
A a(5);
std::cout << (a == A(5)) << std::endl;
std::cout << (a == 5) << std::endl;
}
The first line works, the number is explicit converted to an "A" and then the comparison operator from std::string
is used to compare the object.
My problem is that I want to avoid the explicit conversion, but if I do it like in the second line, the compiler doesn't recognize the possibility to implicit convert the number and than use the std::string
comparison.
Is there a way to change the class A in such a way, that the implicit convert/comparison work?