如何检查std::cout << myClass;
是否有效?我想做类似的事情:
class Logger {
public:
// Some kind of enable_if(operator<< doesn't exist)
void printMyClass(MyClass& my_class) {
std::cout << "Got a myclass" << std::endl;
}
// Some kind of enable_if(operator<< exists)
void printMyClass(MyClass& my_class) {
std::cout << "Got a myclass: " << my_class << std::endl;
}
};