Templated Functions.. ERROR: template-id does not match any template declaration

前端 未结 2 1812
鱼传尺愫
鱼传尺愫 2021-01-19 00:28

I have written a function template and an explicitly specialized templated function which simply takes in 3 arguments and calculates the bi

相关标签:
2条回答
  • 2021-01-19 01:15

    I ran into the same problem and fixed it by using typedef:

    typedef char * charPtr;
    template <>
    void Max(charPtr &a, charPtr &b, charPtr &c)
    
    0 讨论(0)
  • 2021-01-19 01:28

    You need to take the pointers by reference:

    template <> 
    void Max(char*& a,char*& b,char*& c) 
    

    That said, it would be better not to use an explicit specialization and instead just overload the function:

    void Max(char* a, char* b, char* c)
    

    It's almost always a bad idea to specialize function templates. For more, see Herb Sutter's "Why Not Specialize Function Templates?"

    0 讨论(0)
提交回复
热议问题