template specialization multiply defined symbols

前端 未结 3 1357
日久生厌
日久生厌 2020-12-29 23:56

I know i\'m missing something easy here but I\'ve got a templated member function of a class which I\'ve specialised.

MyClass
{
    template

        
3条回答
  •  鱼传尺愫
    2020-12-30 00:23

    I would suggest you to remove the following implementation from your code altogether, so that compiler can generate error at compile-time itself if T is not int . Early detection of error is better than delay detection(which is done at runtime).

    template
    T MyClass::GetTFromVariable(shared_ptr v, string s)
    {
        throw std::runtime_error("Don't know how to convert " + ToString(v->GetString()));
    }
    

    There is exactly similar topic/issue discussing this thing. Please have a look at this:

    Partial template specialization for specific type, c++

提交回复
热议问题