Answers for "c++ overriding operator"

C++
0

operator = overloading c++

inline bool operator==(const X& lhs, const X& rhs){ /* do actual comparison */ }
inline bool operator!=(const X& lhs, const X& rhs){ return !(lhs == rhs); }
Posted by: Guest on April-18-2021
1

c++ overload < operator

struct Foo
{
    double val;
    friend bool operator<(const Foo& l, const Foo& r)
    {
      	//Custom comparison for l < r goes here
        return l.val < r.val; 
    }
};
Posted by: Guest on March-16-2021

Browse Popular Code Answers by Language