我正在尝试使用QtConcurrent::mapped,但我无法使其工作。这应该很简单:
class ChainInfo {
};
class Chain {
public:
ChainInfo GetInfo() const;
};
void CalculateInfo(QList<Chain *> Chains) const {
auto GetChainInfo = [](Chain const *pChain) {
return pChain->GetInfo();
};
auto ChainInfos = QtConcurrent::mapped(Chains, GetChainInfo);
}我得到以下编译错误:
QtConcurrent/qtconcurrentmapkernel.h(162): error C2039: 'result_type': is not a member of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
Link.cpp(193): note: see declaration of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
QtConcurrent/qtconcurrentmapkernel.h(213): note: see reference to class template instantiation 'QtConcurrent::MappedEachKernel<QList<Chain *>::const_iterator,Functor>' being compiled
with
[
Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
]
QtConcurrent/qtconcurrentmapkernel.h(237): note: see reference to class template instantiation 'QtConcurrent::SequenceHolder1<Sequence,QtConcurrent::MappedEachKernel<QList<Chain *>::const_iterator,Functor>,Functor>' being compiled
with
[
Sequence=QList<Chain *>,
Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
]
qtconcurrent\qtconcurrentmap.h(132): note: see reference to function template instantiation 'QtConcurrent::ThreadEngineStarter<void> QtConcurrent::startMapped<void,Sequence,T>(const Sequence &,Functor)' being compiled
with
[
Sequence=QList<Chain *>,
T=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>,
Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
]
Link.cpp(195): note: see reference to function template instantiation 'QFuture<void> QtConcurrent::mapped<QList<Chain *>,CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>>(const Sequence &,MapFunctor)' being compiled
with
[
Sequence=QList<Chain *>,
MapFunctor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
]
QtConcurrent/qtconcurrentmapkernel.h(162): error C2146: syntax error: missing '>' before identifier 'result_type'
QtConcurrent/qtconcurrentmapkernel.h(165): error C2039: 'result_type': is not a member of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
Link.cpp(193): note: see declaration of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
QtConcurrent/qtconcurrentmapkernel.h(165): error C3646: 'T': unknown override specifier
QtConcurrent/qtconcurrentmapkernel.h(165): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
QtConcurrent/qtconcurrentmapkernel.h(167): error C3646: 'ReturnType': unknown override specifier
QtConcurrent/qtconcurrentmapkernel.h(167): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
QtConcurrent/qtconcurrentmapkernel.h(237): error C2440: 'return': cannot convert from 'QtConcurrent::ThreadEngineStarter<int>' to 'QtConcurrent::ThreadEngineStarter<void>'
QtConcurrent/qtconcurrentmapkernel.h(237): note: No constructor could take the source type, or constructor overload resolution was ambiguous
dpclosedguielement.cpp
dpclusterelement.cpp
dpdimensioncontroller.cpp
dpexternaldocumentsload.cpp
dpflowsymbol.cpp
dpguilink.cpp
dpguisymbol.cpp你知道可能出了什么问题吗?
发布于 2020-01-15 15:56:10
我可以通过指定lambda函数的类型来解决这个问题,而不是仅仅使用auto
std::function<ChainInfo(Chain const *)> GetChainInfo = [](Chain const *pChain) {
return pChain->GetInfo();
};https://stackoverflow.com/questions/59736814
复制相似问题