How to connect to a boost::signal with a void returning function?

Hi All,

I'm trying to connect a simple void returning function to multiple signals of varying signature, I can see some references mentioning its possible using boost:lambda::bind, But I keep getting compilation errors, Is there something wrong with the following code? Or is there a better way to do it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <boost/signals2.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
using namespace boost::signals2;

void func()
{
  printf("Func called!");
}

main()
{
  signal<int(int)> sig;
  sig.connect( (boost::lambda::bind(func),  1) );
}


I'm getting the following compilation errors:

1
2
3
4
5
/opt/include/boost/signals2/detail/slot_template.hpp: In member function ‘void boost::signals2::slot1<R, T1, SlotFunction>::init_slot_function(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’:
/opt/include/boost/signals2/detail/slot_template.hpp:81:9:   instantiated from ‘boost::signals2::slot1<R, T1, SlotFunction>::slot1(const F&) [with F = int, R = int, T1 = int, SlotFunction = boost::function<int(int)>]’
hello-world-example.cpp:13:51:   instantiated from here
/opt/include/boost/signals2/detail/slot_template.hpp:156:9: error: invalid conversion from ‘int’ to ‘boost::function<int(int)>::clear_type*’ [-fpermissive]
/opt/include/boost/function/function_template.hpp:1110:14: error:   initializing argument 1 of ‘boost::function<R(T0)>::self_type& boost::function<R(T0)>::operator=(boost::function<R(T0)>::clear_type*) [with R = int, T0 = int, boost::function<R(T0)>::self_type = boost::function<int(int)>]’ [-fpermissive]



Many thanks,
Sak
Last edited on
It compiles with only one warning on my compiler:
the compiler wrote:
11 6 C:\Users\Vilim\Desktop\New folder\Neimenovano1.cpp [Warning] ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
Topic archived. No new replies allowed.