how to query if(T==int) with template class

前端 未结 9 1748
猫巷女王i
猫巷女王i 2020-12-13 19:43

When I\'m writing a function in a template class how can I find out what my T is?

e.g.

template 
ostream& operator << (os         


        
9条回答
  •  温柔的废话
    2020-12-13 20:20

    This way.

    ostream & operator << (ostream &out, Vector const & vec)
    {
        // ...
    }
    

    The compiler will choose this function over the function template if you pass Vector.

    Edit: I found this article, which attempts to explain why to prefer overloading to template specialization.

提交回复
热议问题