S
saneman
I have declared a binary non-member operator+ in the below class.
class superBob {
public:
superBob(int a) : n(a) {}
int getInt() const {
return n;
}
friend int operator+(int,int);
protected:
int n;
};
I have read that non-member binary operators takes two arguments, but
when compiling I get:
‘int operator+(int, int)’ must have an argument of class or enumerated type
As the error indicates one of the arguments must be of class or
enumerated type. Redefining to:
friend int operator+(const superBob&, int);
compiles without error. But why does one of the arguments have to be of
class or enumerated type?
class superBob {
public:
superBob(int a) : n(a) {}
int getInt() const {
return n;
}
friend int operator+(int,int);
protected:
int n;
};
I have read that non-member binary operators takes two arguments, but
when compiling I get:
‘int operator+(int, int)’ must have an argument of class or enumerated type
As the error indicates one of the arguments must be of class or
enumerated type. Redefining to:
friend int operator+(const superBob&, int);
compiles without error. But why does one of the arguments have to be of
class or enumerated type?