为什么要有 void QList::push_back ( const T & value )
在 QT 中,当它做与 append()
相同的事情时,文档意味着什么样的兼容性。谁能详细说明一下
以下为官方声明documentation的QT
“这个函数是为了兼容STL而提供的,等同于append(value)”
最佳答案
这通常用于使期望标准容器作为其模板参数的方法模板可以与 QList
一起使用同样,因为它们将共享相同的方法。
例如:
template<typename Container>
void move_elements(Container &to, const std::vector<int> &from)
{
for (auto elem : from)
to.push_back(elem);
}
可以同时调用 std::list<int>
和一个 QList<int>
作为to
参数。
关于c++ - 为什么 QT 的 QList 方法与 std::list 兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17989970/