Using template for return value. how to handle void return?

后端 未结 2 1944
無奈伤痛
無奈伤痛 2021-02-05 07:46

I have structure for storing callback function like this:

template
struct CommandGlobal : CommandBase
{
    typedef boost::function Co         


        
2条回答
  •  盖世英雄少女心
    2021-02-05 08:20

    If it's just the return statement, this should do the trick:

    virtual T Execute() const
    {
        if(comm)
            return comm();
        return T();
    }
    

    If there's more to it, specialize the template for void.

提交回复
热议问题