如何使用运算符在同一行中多次调用函数
How to call a function several times in the same line using an operator
此函数将TElement
添加到vector<TElement>
:
friend void operator<<(ToDo& todu, const ElementT& D) {
todu.add(D);
return;
}
我想这样称呼它:
todo << elem1 << elem2 << elem3 << elem4...
如果你想像这样链接操作,那么你可以简单地通过引用返回ToDo
参数,如下所示:
friend ToDo& operator<<(ToDo& todu, const ElementT& D)
{
todu.add(D);
return todu;
}
现在你应该能够像这样使用operator<<
:
todo << elem1 << elem2 << elem3 << elem4;
相关文章:
- 如何使用运算符在同一行中多次调用函数
- uncrustify:如何将多行 C 函数调用的参数组合到一行上?
- 使用更改此变量的函数在同一行中打印引用变量
- Ofstream一直给我函数的最后一行,而不是显示所有内容
- C++将函数指针放入一行的映射中
- C++ 两个函数除了一行之外执行相同的操作
- 将地址返回到 2D 数组中的一行值的函数
- 无法理解代码的特定片段:这是一个函数,只是一行还是什么
- 线程1:EXC_BAD_ACCESS错误,此错误在第一行的CPP文件中的句柄函数中出现
- 当两个函数位于一行中时,堆栈框架的样子
- 如何将具有多行代码的内联函数视为一行?
- 为什么这个函数从不超出第一行
- 无法弄清楚为什么只从文件中读取一行矩阵以及为什么我无法将 2D 数组传递给函数
- clang format函数和错误检查在同一行
- 从函数结果中分配 std::shared_ptr 的一行是什么?
- 当const在另一行处的const时,doxygen parse const成员函数不正确
- 为什么在同一行上有 2 个函数调用时跳过函数调用
- 在文件中返回一行的函数
- getline函数只读取第一行
- C++ 函数删除一行