我认为迭代器的意义在于它们是*它们的基础类型?

时间:2017-11-06 20:42:42

标签: c++

我有以下

Caused by: org.springframework.security.authentication.CredentialsExpiredException: Authentication statement is too old to be used with value 2017-11-06T17:49:26.721Z
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAuthenticationStatement(WebSSOProfileConsumerImpl.java:538)
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.verifyAssertion(WebSSOProfileConsumerImpl.java:306)
  at org.springframework.security.saml.websso.WebSSOProfileConsumerImpl.processAuthenticationResponse(WebSSOProfileConsumerImpl.java:214)
  ... 75 more

问题是此代码无法编译。

当我打电话给doTheThing(模式)时,我收到错误;

错误是:

  

无法从'std :: _ Vector_const_iterator< _Myvec>'转换参数1   'const EMode'

我很茫然,因为我的知识模式应该是一个矢量迭代器,当我尝试使用它调用doTheThing(模式)时应该解析为EMode;

我错过了什么?

2 个答案:

答案 0 :(得分:8)

迭代器与基础数据的类型不同。他们取消引用到该类型。

而不是

doTheThing(mode);

使用

doTheThing(*mode);

答案 1 :(得分:2)

如果你有一个向量,迭代器是指针泛化到T.(也就是说,它们可能不是实际的指针,但可能是充当它的类如果他们是指针),用*和 - >取消引用像指针一样,可递增(如果是正向迭代器),通过任意跳转指针算术(如果是随机访问迭代器),可递减(如果是双向),等等。

myVector.push_back(someObject);
auto iter = myVector.begin();
if (*iter == myVector[0]) // will be true unless operator== is weird for T
  ...