You need a free function, defined after the class
struct A
{
// ...
};
A operator+(int i, const A& a)
{
return a+i; // assuming commutativity
};
also, you might consider defining A& operator+=(int i);
in A
an implement both versions of operator+
as free functions. You might also be interested in Boost.Operators or other helpers to simplify A
, see my profile for two options.