Aquarius_Girl
Aquarius_Girl

Reputation: 22926

How to make the left operand of the operator << a function?

void operator<< (const Integer& left, const Integer& right)
{
    cout << "\n: " << right.i;
}

can be accessed like:

Integer obj;
obj << 5 << 3 << 2;

Fine:

But qDebug works like qdebug() << 2;

Which means that the left operand of << operator is a function.

What should be the syntax of a user defined function so that I can write:
myfunc() << 2;

Upvotes: 0

Views: 279

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726639

The left operand is not a function, it is the value the function returns. Specifically, qDebug() returns an instance of QDebug, which has some 20 overloads of << defined.

Upvotes: 5

Related Questions