어떻게 boost :: bind를 배열 첨자로 사용할 수 있습니까? 여기 내가 성취하려고하는 것이있다. 제발 조언.boost :: bind 출력을 배열 첨자로 사용하기
[servenail : C++의 progs] $ g ++ -v로 구성 /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
에서
읽기 사양 : ../configure - 접두어 =/usr --mandir =/usr/share/man --infodir =/usr/share/info - 사용 가능 공유 - 사용 가능 스레드 = posix - 사용 불가 검사 --with-system-zlib - enable -__ cxa_atexit --disable-libunwind-exceptions --enable-java-awt = gtk --host = i386-redhat-linux
스레드 모델 : posix
gcc 버전 3.4.6 20060404 (Red Hat 3.4.6-3)
[servenail: C++Progs]$ cat t-array_bind.cpp
#include <map>
#include <string>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <iostream>
using namespace std;
using namespace boost;
using namespace boost::lambda;
class X
{
public:
X(int x0) : m_x(x0)
{
}
void f()
{
cout << "Inside function f(): object state = " << m_x << "\n";
}
private:
int m_x;
};
int main()
{
X x1(10);
X x2(20);
X* array[2] = {&x1, &x2};
map<int,int> m;
m.insert(make_pair(1, 0));
m.insert(make_pair(2, 1));
for_each(m.begin(),
m.end(),
array[bind(&map<int,int>::value_type::second, _1)]->f());
}
[servenail: C++Progs]$ g++ -o t-array_bind t-array_bind.cpp t-array_bind.cpp: In function `int main()': t-array_bind.cpp:40: error: no match for 'operator[]' in
'array[boost::lambda::bind(const Arg1&, const Arg2&) [with Arg1 = int std::pair::*, Arg2 = boost::lambda::lambda_functor >](((const boost::lambda::lambda_functor >&)(+boost::lambda::::_1)))]'
고마워요.
예, 저는 bind가 함수 객체를 반환한다는 사실을 알고 있습니다. 내 목표를 분명히하기 위해 원래 코드를 이런 식으로 작성했습니다. 나는 이것이 별도의 함수 호출없이 이루어질 수 있다면 좋겠다. 나는 그렇지 않다. – posharma