【问题标题】:[C++ STL]-pair<vector-iter,int*> - mismatch - no matching function [closed][C++ STL]-pair<vector-iter,int*> - mismatch - no matching function [closed]
【发布时间】:2014-08-25 16:22:00
【问题描述】:
int nums[] = { 4096,64,55,23,544,23,44,556,75,33,23,23};
    //nums + sizeof(nums)/sizeof(int)
    pair<vector<int>::iterator,int*> pr;
   pr = mismatch (p6store.begin(),p6store.end(),nums); //ERROR HERE

C:\WS8_SRV\server_aplt\src\include\c++\3.4.2\bits\stl_pair.h 在构造函数中 `std::pair<_t1 _t2>::pair(const std::pair<_u1 _u2>&) [with _U1 = __gnu_cxx::__normal_iterator >>, _U2 = int*, _T1 = __gnu_cxx::__normal_iterator >>, _T2 = int*]':

90 C:\WS8_SRV\server_aplt\src\include\c++\3.4.2\bits\stl_pair.h 没有匹配函数调用`__gnu_cxx::__normal_iterator >>::__normal_iterator(const __gnu_cxx::__normal_iterator >> &)'

我不明白那个 sn-p 有什么问题

我已经包含了向量、实用程序和算法。

谢谢

编辑:完整代码

vector<unsigned long long int> p6store(350);

init_sq_generator(0);
generate(p6store.begin(),p6store.end(),sq_generator);

for_each(p6store.begin(),p6store.end(),print_val);
int nums[] = { 4096,64,55,23,544,23,44,556,75,33,23,23};

【问题讨论】:

  • p6store 是什么? mismatch 是什么?换句话说,发布MCVE
  • 那个 sn-p 不完整。例如 p6store 没有定义。这就是那个 sn-p 的问题。
  • Can I use mismatch to compare vector which stores ull(unsigned long long) int with an normal int array vector&lt;T&gt;vector&lt;U&gt;U 的数组是两种不同的类型。 TU 是否具有相似的属性(即整数)并不重要。

标签: c++ algorithm stl


【解决方案1】:

std::vector&lt;unsigned long long int&gt;std::vector&lt;int&gt;不一样

因此,std::vector&lt;unsigned long long int&gt;::iteratorstd::vector&lt;int&gt;::iterator 不同。

你应该使用:

std:pair<std::vector<unsigned long long int>::iterator,int*> pr;

std::pair<decltype(p6store.begin()),int*> pr;

或(最好的):

auto pr = std::mismatch(p6store.begin(), p6store.end(), nums);

【讨论】:

  • 它与 ull 一起工作。我很好奇并尝试了 decltype 代码并得到“35 `p6store' cannot appear in a constant-expression” - “函数调用不能出现在常量表达式中”
  • @Yashas Samaga:decltype 示例:ideone.com/huVXDp
  • 我用你的代码做了一个新程序,还是一样的错误,有什么限制吗?
  • 你的编译器支持 C++11 吗?
猜你喜欢
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多