ITeye博客

C/C++

共 2 篇文章

使用 libevent 实现定时器(timer)

#include <event.h> #include <stdio.h> #include <time.h> static void hello(int fd, short event, void *arg) { printf("hello man\n"); } int main(int argc, const char *argv[]) { struct event_base *base; struct timeval tm; struct event evt; evutil_timerclear(&tm); tm.tv_sec = 10; base = event_base_new()…

2013-07-12 18:46 · Linux · C/C++ · Linux · Timer · libevent

【转】C++重载运算符

必要性 :C++中预定义的运算符其运算对象只能是基本数据类型,而不适用于用户自定义类型(如类)。 (一) C++不允许用户自己定义新的运算符,只能对已有的C++运算符进行重载 (二) C++允许重载的运算符C++中绝大部分的运算符允许重载 不能重载的运算符只有5个 : (1) 成员访问运算符. (2) 作用域运算符∷ (3) 条件运算符?: (4) 成员指针运算符* (5) 编译预处理命令的开始符号#( 转者按 :应该是 sizeof 运算符) (三) 重载不能改变运算符运算对象(即操作数)的个数 (四) 重载不能改变运算符的优先级别 (五) 重载运算符的函数不能有默认的参数,否则就改变了运…

2013-03-09 19:19 · C/C++ · C · C++ · 运算符 · 重载