转载请注明出处:http://blog.csdn.net/awebkit 1 c++中的静态函数,以前觉得应该可能会先调用一下参数为空的构造函数,后来发现不是这样,代码如下 class A { public: static void staticFunc(){printf("static func\n");} A(int a):m_a(a){printf("A(int)\n");} private: A(){printf("A()\n");} int m_a; }; int main() { A::staticFunc(); return 0; } 2 bitfield(位域)操作的问题。一定要定义unsigned int,而不是int 代码如下 struct USER { //尝试把下面的unsigned去掉,你会得到不同的结果 unsigned int a:1; unsigned int flag:2; bool test:1; }; int main() { struct USER myuser; memset(&myuser, 0, sizeof(myuser)); myuser.a = 1; myuser.flag = 3; myuser.test = true; printf("myuser test is %d\n", myuser.test); printf("myuser a is %x\n", myuser.a); printf("myuser flag is %d\n", myuser.flag); return 0; }