看起来 QtConcurrent 在 QT 容器(QList
和 QVector
)上工作得很好,但在 STL 容器上却失败了,这与所声称的 在文档中
以下是我想在容器上使用的虚拟函数:
void addOne(int & i)
{
++i;
}
int addOneC(const int & i)
{
return i+1;
}
有效示例:
int main( int argc, char** argv )
{
// Qt containers
QList<int> l;
l << 1 << 2 << 4 << 3;
QList<int> l1 = QtConcurrent::blockingMapped(l, addOneC);
QtConcurrent::blockingMap(l1, addOne);
// Standard containers
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(4);
v.push_back(3);
QtConcurrent::blockingMap(v, addOne);
}
什么不起作用:
int main( int argc, char** argv )
{
// Standard containers
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(4);
v.push_back(3);
vector<int> v1 = QtConcurrent::blockingMapped(v, addOneC);
}
它会导致编译错误,并出现极其长且令人困惑的模板错误。
如果有人知道为什么,那真的会有帮助!谢谢!
错误日志:
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : 错误 C2825: '_Alloc': 后跟 '::' 时必须是类或命名空间
1> .\main.cpp(187) :请参阅类模板实例化 'std::_Container_base_aux_alloc_real<_Alloc>' 的引用正在编译中
1>和
1> [
1> _Alloc=整数
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : 错误 C2903: 'rebind' : 符号既不是类模板也不是函数模板
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442):错误 C2039:“重新绑定”:不是“全局命名空间”的成员
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442):错误 C2143:语法错误:缺少“;”在“<”之前
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442):错误 C2039:“其他”:不是“全局命名空间”的成员
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : 错误 C2238: ';' 前面的意外标记
1>.\main.cpp(187) : 错误 C2248: 'std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real' : 无法访问类 'std::_Container_base_aux_alloc_real<_Alloc>' 中声明的受保护成员
1>和
1> [
1> _Alloc=整数
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(435) :请参阅“std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real”的声明
1>和
1> [
1> _Alloc=整数
1> ]
1>.\main.cpp(187) : 错误 C2440: '初始化' : 无法从 'std::_Container_base_aux_alloc_real<_Alloc>' 转换到 'std::vector<_Ty>'
1>和
1> [
1> _Alloc=整数
1> ]
1>和
1> [
1> _Ty=整数
1> ]
1>没有构造函数可以采用源类型,或者构造函数重载解析不明确
It seems that QtConcurrent works fine with QT containers (QList
and QVector
), but fails with the STL containers, as opposed to what is claimed in the documentation
Here are the dummy functions I want to use on my containers :
void addOne(int & i)
{
++i;
}
int addOneC(const int & i)
{
return i+1;
}
Examples of what works :
int main( int argc, char** argv )
{
// Qt containers
QList<int> l;
l << 1 << 2 << 4 << 3;
QList<int> l1 = QtConcurrent::blockingMapped(l, addOneC);
QtConcurrent::blockingMap(l1, addOne);
// Standard containers
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(4);
v.push_back(3);
QtConcurrent::blockingMap(v, addOne);
}
What does not work :
int main( int argc, char** argv )
{
// Standard containers
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(4);
v.push_back(3);
vector<int> v1 = QtConcurrent::blockingMapped(v, addOneC);
}
It cause a compilation error with atrociously long and obfuscate template errors.
If anyone knew why, it would really help! Thanks!
The error log :
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2825: '_Alloc': must be a class or namespace when followed by '::'
1> .\main.cpp(187) : see reference to class template instantiation 'std::_Container_base_aux_alloc_real<_Alloc>' being compiled
1> with
1> [
1> _Alloc=int
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2903: 'rebind' : symbol is neither a class template nor a function template
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2039: 'rebind' : is not a member of 'global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2143: syntax error : missing ';' before '<'
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2039: 'other' : is not a member of '
global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2238: unexpected token(s) preceding ';'
1>.\main.cpp(187) : error C2248: 'std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real' : cannot access protected member declared in class 'std::_Container_base_aux_alloc_real<_Alloc>'
1> with
1> [
1> _Alloc=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(435) : see declaration of 'std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real'
1> with
1> [
1> _Alloc=int
1> ]
1>.\main.cpp(187) : error C2440: 'initializing' : cannot convert from 'std::_Container_base_aux_alloc_real<_Alloc>' to 'std::vector<_Ty>'
1> with
1> [
1> _Alloc=int
1> ]
1> and
1> [
1> _Ty=int
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
发布评论
评论(1)
我认为您应该明确地将容器的类型赋予
blockingMapped
。编译并给出您给出的简单示例中的预期结果。
I think you should explicitly give the type of the container to the
blockingMapped
.Compile and give me the expected result in the simple example you gave.