开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜