Overriding return type in function template specialization

前端 未结 4 1686
深忆病人
深忆病人 2020-12-04 07:49

I would like to specialize a function template such that the return type changes depending on the type of the template argument.

class ReturnTypeSpecializati         


        
4条回答
  •  余生分开走
    2020-12-04 08:21

    You can do template specializations like so:

    template
    T item() {
        return T();
    }
    
    template<>
    float item() {
        return 1.0f;
    }
    

提交回复
热议问题