S
Sanatan
Hi,
I am trying to implement a multicast callbach dispatcher using
boost::function.
My test programme looks like:
#include <iostream>
#include <list>
#include <boost/function.hpp>
#include <boost/bind.hpp>
using namespace std;
template <class T> class feed
{
list<boost::function<void (T)> > actions;
typedef boost::function<void (T)> cbk;
public:
void deliver(T data)
{
for (typename list<boost::function<void (T)> >::iterator a =
actions.begin();
a != actions.end(); ++a)
{
(*a)(data);
}
}
void register(boost::function<void (T)> act)
{
actions.push_bach(act);
}
};
void callback(pair<double, long> data)
{
cout << "Data (" << data.first << "," << data.second << ")" << endl;
}
int main(int, char **)
{
feed<pair<double, long> > f;
boost::function<void (pair<double, long>)> cbk = callback;
f.register(cbk);
f.deliver(make_pair<double, long>(10.33, 20));
return 0;
}
I am trying to compile with:
g++ -g -o testmcast testmcast.cpp
which yields:
sanat@fractal:~/at/research/src$ g++ -g -o testmcast testmcast.cpp
testmcast.cpp:21: error: invalid declarator before ‘act’
testmcast.cpp:21: error: expected `)' before ‘act’
testmcast.cpp: In function ‘int main(int, char**)’:
testmcast.cpp:34: error: expected unqualified-id before ‘register’
testmcast.cpp:34: error: expected `;' before ‘register’
This seems very strange!
What am I doing wrong?
Any insight would be appreciated.
Thanks!
--Sanatan
I am trying to implement a multicast callbach dispatcher using
boost::function.
My test programme looks like:
#include <iostream>
#include <list>
#include <boost/function.hpp>
#include <boost/bind.hpp>
using namespace std;
template <class T> class feed
{
list<boost::function<void (T)> > actions;
typedef boost::function<void (T)> cbk;
public:
void deliver(T data)
{
for (typename list<boost::function<void (T)> >::iterator a =
actions.begin();
a != actions.end(); ++a)
{
(*a)(data);
}
}
void register(boost::function<void (T)> act)
{
actions.push_bach(act);
}
};
void callback(pair<double, long> data)
{
cout << "Data (" << data.first << "," << data.second << ")" << endl;
}
int main(int, char **)
{
feed<pair<double, long> > f;
boost::function<void (pair<double, long>)> cbk = callback;
f.register(cbk);
f.deliver(make_pair<double, long>(10.33, 20));
return 0;
}
I am trying to compile with:
g++ -g -o testmcast testmcast.cpp
which yields:
sanat@fractal:~/at/research/src$ g++ -g -o testmcast testmcast.cpp
testmcast.cpp:21: error: invalid declarator before ‘act’
testmcast.cpp:21: error: expected `)' before ‘act’
testmcast.cpp: In function ‘int main(int, char**)’:
testmcast.cpp:34: error: expected unqualified-id before ‘register’
testmcast.cpp:34: error: expected `;' before ‘register’
This seems very strange!
What am I doing wrong?
Any insight would be appreciated.
Thanks!
--Sanatan