Implement the operator overloading outside of the class:
class Num
{
public:
Num(int i)
{
this->i = i;
}
int i;
};
int operator+(int i, const Num& n)
{
return i + n.i;
}
More Related Contents:
- Difference between this. and this->
- What are the basic rules and idioms for operator overloading?
- C++ [] array operator with multiple arguments?
- Making operator
- Why is “operator void” not invoked with cast syntax?
- What is the difference between the dot (.) operator and -> in C++? [duplicate]
- What does the question mark character (‘?’) mean in C++?
- How should I write ISO C++ Standard conformant custom new and delete operators?
- std::endl is of unknown type when overloading operator
- How to properly overload the
- Implementing comparison operators via ‘tuple’ and ‘tie’, a good idea?
- Overload resolution failure when streaming object via implicit conversion to string
- How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers
- Overloading friend operator
- Why istream object can be used as a bool expression?
- Why can’t you overload the ‘.’ operator in C++?
- Trouble with inheritance of operator= in C++
- How can I reliably get an object’s address when operator& is overloaded?
- The copy constructor and assignment operator
- The tilde operator in C
- Operator overloading outside class [duplicate]
- Why does the expression a = a + b – ( b = a ) give a sequence point warning in c++?
- difference between global operator and member operator
- Const and Non-Const Operator Overloading
- Overloading assignment operator in C++
- explicit conversion operator error when converting generic lists
- How to call custom operator with Reflection
- Overloading operator
- How to overload operator==() for a pointer to the class?
- friend declaration declares a non-template function [duplicate]