02 2012 档案

#与##的用法
摘要:这两个符号很少被用到,不过很有意思。#:转换成字符串定义一个宏:#define to_string( s ) # s使用cout << to_string(Hello World!) << endl;相当于 cout<<"hello world"<<endl;##:连接你想连接的定义宏:#define concatenate( x, y ) x ## y使用int xy = 10;cout<<concatenate(x,y)<<endl;即使未知的东西, ##也能给连接起来了,可见其变态之处。 阅读全文

posted @ 2012-02-22 14:47 陈朋 阅读(6267) 评论(0) 推荐(0)

STL sort的危险之处
摘要:STL可以进行自动排序,调用algorithm里面的sort函数。但该方法的调用需要一些前提。STL::sort要求被排序的对象必须是顺序确定的。例如:class TestClass { public: int a; int b; bool operator < (const TestClass& rhs) { return this->a < rhs.a; }};因为两个给定的Test1对象, 调用<的时候的结果是一致的。但是如果以下情况:class TestClass { public: int a; int b; bool o... 阅读全文

posted @ 2012-02-17 15:40 陈朋