如何使操作符的左操作数<<一个函数

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

本文关键字:一个 函数 何使 操作数 操作符      更新时间:2023-10-16
void operator<< (const Integer& left, const Integer& right)
{
    cout << "n: " << right.i;
}

可以像这样访问:

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

好:

但是qDebugqdebug() << 2;一样

表示<<操作符的左操作数是一个函数。

用户定义函数的语法应该是什么,这样我才能写:
myfunc() << 2;

左操作数不是函数,它是函数返回的值。具体来说,qDebug()返回一个QDebug的实例,它定义了<<的20个重载。