Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 C++ 新手,我正在尝试弄清楚如何执行以下操作:
我有一个包含 QList 的类。我正在尝试填充 QList,如下所示。我想知道我将如何实现这一目标?这是在 NumberList 构造函数中完成的吗?我通常会使用获取对象列表的方法填充 myList,然后提取它们以填充 QList,但这不适用于下面的示例。
NumberList myList; myList << 1 << 2 << 3;
简单的。
NumberList & operator<<(NumberList & lhs, number_t rhs) { lhs.append(rhs); return lhs; }
或者,作为成员函数,它看起来像这样:
NumberList & NumberList::operator<<(number_t rhs) { append(rhs); return *this; }