Operators can be chained normally: if you have operator + defined for adding two Widgets and returning a Widget, you can add as many Widgets with it as you like. The reason is simple:
a + b + c + d
is parsed as
((a + b) + c) + d
However, there's something wrong with your operator declaration: you're returning a reference to a Movie. That makes no sense for an operator like +, which creates a new value rather than modify an existing one. You should be creating a separate Movie object inside the operator, and returning it by value.
Generally, the best way of handling operators like this is to implement the operation&assignment variant in class, and building the binary operator as a non-member function on top of that. Something like this:
class Movie
{
// ...
Movie& operator+= (const Movie &rhs)
{
//somehow add rhs to this
return *this;
}
// ...
};
inline Movie operator+ (const Movie &lhs, const Movie &rhs)
{
Movie result = lhs;
result += rhs;
return result;
}
There's one more point: though. What does it mean to add two movies together in the first place? Overloading operators for the sake of shorter syntax for some arbitrary, unituitive operation leads to unreadable and hence unmaintainable and hence bad code.
Unless you're building a DSL (which you're probably not), I'd stick with named functions for the sake of maintainability.
Movie? It should be a non-member function.operator+. Are you sure you don't want to return by value?operator+()... first definition handles the condition you are talking about... think whyMovie&is returned...operator+(const Movie& other)is all you need to be able to writemovie1+movie2+movie2...