Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Non-member oper...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 43343 of 47561
Post > Topic >>

Non-member operators

by saneman <yyyy@[EMAIL PROTECTED] > Feb 15, 2008 at 11:30 PM

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?
 




 2 Posts in Topic:
Non-member operators
saneman <yyyy@[EMAIL P  2008-02-15 23:30:40 
Re: Non-member operators
"Victor Bazarov"  2008-02-15 17:36:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 4:17:12 CDT 2008.