Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lidaobing
Created March 28, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidaobing/f5dec5839606f0e612f95f743c37967d to your computer and use it in GitHub Desktop.
Save lidaobing/f5dec5839606f0e612f95f743c37967d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sigc++/signal.h>
using namespace std;
class A {
public:
sigc::signal<void()> s1;
};
class B {
public:
~B() { cout << "B::~B()" << endl; }
void onS1() { cout << "B::onS1: SHOULD NOT PRINT" << endl; }
};
class C: public sigc::trackable {
public:
~C() { cout << "C::~C()" << endl; }
void onS1() { cout << "WILL NOT PRINT" << endl; }
};
int main() {
A a;
B* b = new B;
C* c = new C;
a.s1.connect(sigc::mem_fun(*b, &B::onS1));
a.s1.connect(sigc::mem_fun(*c, &C::onS1));
delete b;
delete c;
a.s1.emit();
}
// $ g++ -std=c++11 `pkg-config --cflags --libs sigc++-2.0` sigc_test.cpp
// $ ./a.out
// B::~B()
// C::~C()
// B::onS1: SHOULD NOT PRINT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment