user394511
user394511

Reputation: 31

Cascading for overloaded + operator

Here's the current code:

const complex complex::operator+(const complex &right)
{
     complex result;
     result.realPart = realPart + right.realPart;
     result.imPart = imPart + right.imPart;
     return result;
}

How do i modify so that

a = b + c + d;

is allowed?

Upvotes: 2

Views: 946

Answers (1)

Marcelo Cantos
Marcelo Cantos

Reputation: 185978

Make it a const member function:

const complex complex::operator+(const complex &right) const ...

Upvotes: 5

Related Questions