You can put these in the private
section of proxy class:
template<typename T>
auto show_helper(int) -> decltype( std::declval<T>().show(), void())
{
cw.show();
}
template<typename T>
void show_helper(...) { }
and call them like this from show
:
show_helper<CustomWidget>(0);
The first overload gets instantiated only if expression in trailing return type is well formed, that is, when T
has got show
method.
This is called expression SFINAE and is much shorter than pre-C++11 version from pmr's answer. It's also more flexible as it lets you specify the signature of show
more easily. The other answer can give you positive result only to discover that you can't call show
without arguments. Pick your poison.