[英]std::map<>::iterator error
I am creating a map: 我正在创建地图:
std::map<TString, TString> cuts;
where TString is a ROOT framework class that stores strings as char* (and has some additional features) that I add to my C++ code with #include "TString.h"
, 其中TString是一个ROOT框架类,将字符串存储为char *(并具有一些其他功能),我使用
#include "TString.h"
将其添加到C ++代码中,
I then create a few cuts map elements: 然后,我创建一些切割图元素:
cuts["cTRIGem0"] = "eminusL0ElectronDecision_TOS>0";
And then try to create an iterator to loop over cuts: 然后尝试创建一个迭代器来循环切割:
std::map<TSring, TSring>::iterator itr = cuts.begin();
This yields a host of errors: 这会产生许多错误:
Wenu.cpp:561:12: error: ‘TSring’ was not declared in this scope
Wenu.cpp:561:26: error: template argument 1 is invalid
Wenu.cpp:561:26: error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
Wenu.cpp:561:26: error: expected a type, got ‘TSring’
Wenu.cpp:561:26: error: template argument 3 is invalid
Wenu.cpp:561:26: error: template argument 4 is invalid
Wenu.cpp:561:38: error: expected initializer before ‘itr’
I saw somewhere that the keyword typename
may help. 我在某处看到关键字
typename
可能会有所帮助。 So I added it to the iterator declaration: 所以我将其添加到迭代器声明中:
std::map<typename TSring, typename TSring>::iterator itr = cuts.begin();
Which gave a new error: 这给了一个新的错误:
Wenu.cpp:561:44: error: wrong number of template arguments (1, should be 4)
/cvmfs/lhcb.cern.ch/lib/lcg/external/gcc/4.6.2/x86_64-slc5/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/stl_map.h:88:11: error: provided for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
Wenu.cpp:561:56: error: expected initializer before ‘itr’
Any help on how to resolve this error and get my iterator working would be much appreciated. 我们将非常感谢您提供有关如何解决此错误并使迭代器正常运行的任何帮助。
You spelled it wrong; 您拼写错误; you want
TString
, not TSring
. 您需要
TString
而不是TSring
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.