I
IndyStef
I am trying to use boost's bind on a member function, on the VC8
compiler.
After using several different attempts, I could not get it to work.
Does
anybody know what is wrong with the code below? The function that
doesn't
compile is foo:oTheStuff. All three variations of the for-each loop
won't
build.
Thank you,
Stefan
// Boost_Bind.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <boost/bind.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
class foo
{
public:
foo() {};
virtual ~foo() {};
void DoTheStuff();
void PrintInt( int a_nI );
protected:
vector<int> m_vecInt;
};
void foo:rintInt(int a_nI )
{
cout << a_nI << endl;
}
void foo:oTheStuff()
{
m_vecInt.reserve(50);
generate(m_vecInt.begin(),m_vecInt.end(),rand);
for_each(m_vecInt.begin(),m_vecInt.end(),boost::bind(&foo:rintInt,
_1));
//for_each(m_vecInt.begin(),m_vecInt.end(),boost::bind<void>(mem_fun(&foo:rintInt),
_1));
//for_each(m_vecInt.begin(),m_vecInt.end(),mem_fun(&foo:rintInt));
}
int _tmain(int argc, _TCHAR* argv[])
{
foo a;
a.DoTheStuff();
return 0;
}
compiler.
After using several different attempts, I could not get it to work.
Does
anybody know what is wrong with the code below? The function that
doesn't
compile is foo:oTheStuff. All three variations of the for-each loop
won't
build.
Thank you,
Stefan
// Boost_Bind.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <boost/bind.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
class foo
{
public:
foo() {};
virtual ~foo() {};
void DoTheStuff();
void PrintInt( int a_nI );
protected:
vector<int> m_vecInt;
};
void foo:rintInt(int a_nI )
{
cout << a_nI << endl;
}
void foo:oTheStuff()
{
m_vecInt.reserve(50);
generate(m_vecInt.begin(),m_vecInt.end(),rand);
for_each(m_vecInt.begin(),m_vecInt.end(),boost::bind(&foo:rintInt,
_1));
//for_each(m_vecInt.begin(),m_vecInt.end(),boost::bind<void>(mem_fun(&foo:rintInt),
_1));
//for_each(m_vecInt.begin(),m_vecInt.end(),mem_fun(&foo:rintInt));
}
int _tmain(int argc, _TCHAR* argv[])
{
foo a;
a.DoTheStuff();
return 0;
}