7 years ago I would write something like that:
#include <iostream>
struct A {};
struct B {
static const char* message;
};
const char* B::message = "Hello, world!";
template <typename T>
void PrintMessage(...) {}
template <typename T>
void PrintMessage(decltype(&T::message)) {
std::cout << T::message << std::endl;
}
int main() {
PrintMessage<A>(nullptr);
PrintMessage<B>(nullptr);
return 0;
}
The solution would work even with Visual C++ 2010 if I recall correctly. Is there any better way of doing that in C++ 17 ?