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

前端 未结 4 1627
轻奢々
轻奢々 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:15

    The declaration of the operator==() is a template. The declaration made a friend is not a template but a non-template. To make the template operator==() a friend you need to make the friend declaration a template, too:

    template  class Point;
    
    template 
    bool operator== (Point, Point);
    
    template 
    class Point {
        // ...
        template 
        friend bool operator== (Point, Point);
    };
    

提交回复
热议问题