I'm trying to create a simple Signals/Slots system in C++ without boost but I've got some problems when I try to use it with parameters, here is my code :
My Signal class :
template <typename T>
class Signal
{
private:
typedef std::function<T> Slot;
public:
Signal();
void connect( Slot slot );
void emit( T data );
void emit();
private:
std::vector<Slot> slots;
};
My Test class :
class Object
{
public:
Object();
void sayHello( int i );
};
So, I use my class like that :
Signal<void(int)> signal;
signal.connect( std::bind( &Object::sayHello, player, std::placeholders::_1 ) );
signal.emit( 0 );
I've got a warning in Signal.cpp : Candidate function not viable: no known conversion from 'void (*)(int)' to 'int' for 1st argument;
In this code :
template <typename T>
void Signal<T>::emit( T data )
{
typename std::vector<Slot>::iterator i;
Slot t;
for( i = this->slots.begin(); i != this->slots.end(); i++ )
{
t = (*i);
t( data ); // Here
}
}
How can I solve that? If I want give an object or multiples parameters to my "emit" method, hoc can i do?
Thanks!