if i do a friend Testclass operator +(Test class &obj2); it is not correct because i need two obj

J

John Cho

if i do a friend Testclass operator +(Test class &obj2); it is not
correct because i need two objects?
 
J

Jonathan Turkanis

John Cho said:
if i do a friend Testclass operator +(Test class &obj2); it is not
correct because i need two objects?

It depends what you want to do. If you declare operator+ as above, you
get a unary operator+ which might be used like this, for example (for
illustration, I'm assuming you also have a binary operator*):

Test a, b, c;
c = +b * a

If you want to be able to write

c = a + b

you need to define a binary operator+, which you might declare as
follows:

Test operator+(const Test&, const Test&);

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top