摘要:
#define TRACE(ARG) cout << #ARG<<endl;TRACE(for(int i=0;i < 100;i ++))TRACE( cout << i << endl;)输出结果是for(int i =0;i < 10;i ++)cout << i << endl; 阅读全文
摘要:
1 #include 2 #include 3 using namespace std; 4 using namespace boost; 5 void hello(){ 6 cout << "hello" << endl; 7 } 8 void f1(){ 9 thread thr1(&hello); 10 thread thr2(&hello); 11 thread thr3(&hello); 12 thread thr4(&hello); 13 thr1.join(); 14 thr2.join(); 15 .. 阅读全文
摘要:
本系统centos 中多进程的编译使用g++ thread.cpp -lboost_thread-mtC++ Boost Thread 编程指南作者:dozbC++ Boost Thread 编程指南0 前言1 创建线程2 互斥体3 条件变量4 线程局部存储5 仅运行一次的例程6 Boost线程库的未来7 参考资料:0 前言标准C++线程即将到来。CUJ预言它将衍生自Boost线程库,现在就由Bill带领我们探索一下Boost线程库。就在几年前,用多线程执行程序还是一件非比寻常的事。然而今天互联网应用服务程序普遍使用多线程来提高与多客户链接时的效率;为了达到最大的吞吐量,事务服务器在单独的线程 阅读全文
摘要:
编译g++ -o hello hello.cpp -lcppunit下面是代码1 /*Program:testcppunit.cpp -- a simple hellow example which use the cppunit tool*/ 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 class Test : public CPPUNIT_NS::TestCase 10 { 11 CPPUNIT_TEST_SUITE(Test); 12 ... 阅读全文
摘要:
class x{ x(int i){}};class y{ y(){}};throw x(100); 此时是抛出一个对象的(正确)throw x ; 此时应该错误的throw y();此时是抛出一个对象;正确throw y;此时错误必须有一对双括号 阅读全文
摘要:
using namespace std; 4 class a{ 5 public: 6 a(int i){} 7 }; 8 9 class b{ 10 public: 11 b(){} 12 }; 13 void f1(){ 14 auto_ptr p1(new a(1)); 15 auto_ptr p2(new b); 16 }class chy{ 44 public: 45 chy(){value ++;} 46 void print(){ 47 c... 阅读全文
摘要:
templateclass a{ 4 public: 5 a(); 6 void printall(); 7 private: 8 int size; 9 T *value; 10 }; 11 template a::a(){ 12 size = i; 13 value = new T [size]; 14 } 15 templatevoid a::printall(){ 16 for(int j=0;j a1;//如果前面已经使用了int i= 10;则如果后面给出了参数,就... 阅读全文
摘要:
所有标准异常归根结底都是从exception类派生而来,此类定义在头文件exception中两个主要的派生类为logic_error(报告程序逻辑错误,通过检查代码,能够发现这类错误)和runtime_error(报告运行错误,只有在程序运行时候,这类错误才能被检查到)这两个类的定义在头文件stdexcept中,通过exception::what()函数,可以从对象中得到他所保存的消息一般不要从exception派生类,而是从logic_error或者runtime_error派生自己的类class x{ 4 public: 5 class a{}; 6 class b{... 阅读全文