1
작동하지 람다 :: 향상에 바인드 내 부스트 람다에 간단한 프로그램은 다음과 같은 오류 밖으로 분출 다음과 같은 :중첩 사용 :
maxInMap.cpp:29:71: instantiated from here /usr/include/boost/lambda/detail/function_adaptors.hpp:264:15: error: invalid initialization of reference of type ‘std::vector<int>&’ from expression of type ‘const std::vector<int>’
문제가 것 등을 이해 도와주세요
,443,132 : 전체 부스트에서 나를 도와 람다,이 문제 오류는 실제로 Boost.Lambda 또는 Boost.Bind 관련이 없습니다#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/if.hpp>
#include <boost/lambda/algorithm.hpp>
#include <boost/lambda/bind.hpp>
using namespace std ;
using namespace boost ;
using namespace boost::lambda ;
int main()
{
map<int, vector<int> > intVecMap ;
int vecSizes[] = {3, 6, 2, 9, 5, 8, 1, 7, 10, 4} ;
for (int i = 0; i < 10; i++)
intVecMap[i] = vector<int>(vecSizes[i], i) ;
map<int, vector<int> >::const_iterator itr =
max_element(intVecMap.begin(), intVecMap.end(),
(bind(&vector<int>::size,
bind(&pair<int, vector<int> >::second, _1)) <
bind(&vector<int>::size,
bind(&pair<int, vector<int> >::second, _2)))) ;
if (itr == intVecMap.end())
cout << "Max Element function could not find any max :-(\n" ;
else
cout << "Max Index = "<<(*itr).first<<" Size = "<<(*itr).second.size()<<endl ;
return 0 ;
}
고마워 조나단을 (그 이유
map
는const
키 유형은 당신이 요소의 키를 수정하여지도의 순서를 무효화. 방지하는 것입니다있다). – user2751632그러면 답을 받아 들여야합니다. –