[sigc] libsigc problems
- From: luca <luca cappa i-medlab com>
- To: libsigc-list gnome org
- Subject: [sigc] libsigc problems
- Date: Tue, 29 Nov 2005 22:20:04 +0100
Hello all,
I explain here two problems i experienced with the latest sigc library.
First of all i cant use no more references as arguments of the bind<>
function since one of the latest sigc library version (i cant remember
now exaclty which was the previous one which references were working
properly with, sorry). Here below i report a test case which does not
compile (gcc4.03) and which uses references:
class X
{
};
class ClassHandler
{
public:
sigc::signal<void> signal;
X x;
ClassHandler ()
{
signal.connect (sigc::bind<X&> (sigc::mem_fun (*this,
&ClassHandler::on), x));
}
~ClassHandler ()
{
std::cout << "~ClassHandler" << std::endl;
signal.clear ();
}
void emitSignal ()
{
signal.emit ();
}
void on (X& x)
{
delete this;
}
};
The second problem is if anyone has a clue on how to redesign better
what i am doing in the following code (which is similar to the test case
above but uses a pointer instead of a reference:
*class* ClassHandler
{
*public*:
sigc::signal<void> signal;
X x;
ClassHandler ()
{
signal.*connect* (sigc::bind<X*> (sigc::mem_fun (**this*, &ClassHandler::on), &x));
}
~ClassHandler ()
{
std::cout << "~ClassHandler" << std::endl;
signal.clear ();
}
void emitSignal ()
{
signal.*emit* ();
}
void on (X* x)
{
*delete* *this*;
}
};
//int main (int argc, char *argv[])
{
ClassHandler lCA;
lCA.emitSignal ();
}
The problem is that when i call "delete this" the program will crash
since i destroyed the object i am emitting the signal from (and also the
slot will be destroyed indeed). Anyone has a better design to avoid this
problem?
Greetings,
Luca
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]