libsigc++-1.2.5库的使用

来源:互联网 发布:p6软件 编辑:程序博客网 时间:2024/06/08 11:11

libsigc++-1.2.5库的使用
下载地址

解压文件

./configure --prefix=/usr

make;make insatll

examples中的简单列子

#include <iostream>#include <string>#include <sigc++/sigc++.h>using namespace std;using namespace SigC;void print(const string &str){cout << str;}main(){Signal1<void,const string &> printer; //定义一个参数为const string&,返回值为void的信号printer.connect(slot(print)); //连接信号和槽printer("hello world\n"); //发送信号,等同于直接调用print函数}
g++ hello.cpp -o hello `pkg-config --cflags --libs sigc++-1.2`

运行结果:hello world

信号的类型SigC::Signal1的模板参数中第一个是返回值类型,后面是信号参数的类型,sigc++.h中提供了Signal0~Signal5,对应函数的参数个数。

0 0