编译时错误之 error C2338: tuple_element index out of bounds

part 1 

  编译器 vs2015 VC++。

  完整的错误信息粘贴如下:

d:\program files (x86)\microsoft visual studio 14.0\vc\include\utility(361): error C2338: tuple_element index out of bounds

  在百度上找了一下,没有中文版解释。我觉得今后把C++编译时遇到的错误及解决方法记录下来会很有裨益。

 

part 2 正文

  错误的代码:

auto it1 = find_if(numbers.cbegin(), numbers.cend(), bind(check_size, "feng", placeholders::_2));

  错误原因

auto newCallable = bind(check_size, "feng", placeholders::_2);

   错误的使用了 placeholdesr::_2 ,其含义是 newCallable 的第二个参数,是暴露给算法的第二个参数。要知道,newCallable 只有一个参数是暴漏的算法的,还没有第一个呢,直接就有了第二个,编译时错误妥妥的!

  如何改正

auto it1 = find_if(numbers.cbegin(), numbers.cend(), bind(check_size, "feng", placeholders::_1));

   把 placeholdesr::_2 改成 placeholdesr::_1。

 

(全文完)

posted @ 2015-10-10 13:29  健康平安快乐  阅读(2337)  评论(0编辑  收藏  举报