Invoke a may not existed member function by template
How can I call a may-existing member function by template technology, I am
not want to use virtual method, because the class is arbitrary.
For example:
class A {
void setValue(int value)
};
How to define a template to call class A's setValue if it existing, else
do nothing.
The template is something like:
template <typename T>
struct call_if_exist {
void invokeOrNot(T& a, int value) // EXISTING: setValue
a.setValue(value);
}
}
template <typename T>
struct call_if_exist {
void invokeOrNot(T& a, int value) // NOT EXISTING: do nothing
}
}
It's about invoking, not checking
No comments:
Post a Comment