How to make a class template argument optional?
Is there any way to make a template class argument optional?
Specifically in this example:template <typename EVT>
class Event : public EventBase {
public:
void raise(EVT data){
someFunctionCall(data);
}
}
I want to have a ver开发者_开发知识库sion of the same template equivalent to this:
class Event : public EventBase {
public:
void raise(){
someFunctionCall();
}
}
But I don't want to duplicate all the code. Is it possible?
With default template argument, and template specialization :
template <typename EVT=void>
class Event : public EventBase {
public:
void raise(EVT data){
someFunctionCall(data);
}
};
template <>
class Event<void> : public EventBase {
public:
void raise(){
someFunctionCall();
}
};
However, I don't see how would the EventBase look like.
精彩评论