how to overload operator == outside template class using friend function?

前端 未结 4 1601
轻奢々
轻奢々 2021-01-15 16:00

I\'m trying to write a template class which overloads operator==. I know how to get it inside the class:

    template 
            


        
4条回答
  •  别那么骄傲
    2021-01-15 16:13

    This is a tricky issue: the friend declaration in the class will define a different friend function for each instantiation of your class. In other words, Point and Point will give rise to 2 different non-template friend functions. On the other hand, the outside function is a template function, not related to the friend inside the class. Solution: define the friend function inside the class. Due to friend name injection, it will be found successfully by ADL.

提交回复
热议问题