• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
demps_c
博客园    首页    新随笔    联系   管理    订阅  订阅
10 2013 档案
why

摘要:38 void f7(istream& in,ostream& out){ 39 // ios_basic::iostate s = cin.rdstate(); 40 int java; 41 for(int i =0;i >java; 43 out >java; 43 out << java << endl; 44 } 45 46 }不可行都是在调用f7(cin,cout);的情况下,为啥用了引用就能,是不是cin和cout不能被复制,如果没有引用就不会复制的原因,而cout和cin是不能被复制的,因为他们是标准的输出输入 阅读全文
posted @ 2013-10-28 16:00 demps_c 阅读(135) 评论(0) 推荐(0)
hh

摘要:try后面必须跟着catch 阅读全文
posted @ 2013-10-23 16:08 demps_c 阅读(103) 评论(0) 推荐(0)
计划

摘要:这个星期整整7天时间看完C++编程思想下个星期整整7天看完squid代码 阅读全文
posted @ 2013-10-21 12:05 demps_c 阅读(89) 评论(0) 推荐(0)
template编程

摘要:templateclass a{ 4 public: 5 a(T t1):value(t1){} 6 static a aa; 7 static int go; 8 T value; 9 static T gone; 10 }; 11 template int a::go = 1; 12 template T a::gone = 1;//一般只有具体的时候才有意义的void f1(){ 15 char val1=11; 16 short val2 = 12; 17 in... 阅读全文
posted @ 2013-10-17 21:58 demps_c 阅读(144) 评论(0) 推荐(0)
构造函数

摘要:如果一个类中有很多成员对象(别的类的对象),则必须在此构造函数中完成构造(不管怎样,编译器会在此构造函数中增加很多代码)如果此类中有一个成员对象(别的类的对象)是需要参数的,则必须要定义构造函数,且明确调用这个成员的构造函数class a{ 4 public: 5 a(){cout <<" a " << endl;} 6 ~a(){cout << " ~a " << endl;} 7 }; 8 9 a& f1(){ 10 a a1; 11 return a1; 12 } 13 int main(){ 阅读全文
posted @ 2013-10-16 22:40 demps_c 阅读(150) 评论(0) 推荐(0)
string

摘要:22 void f3(){ 23 string str1 = "nimei"; 24 string str2; 25 string str3 = "a"; 26 cout << sizeof(str1) << endl << sizeof(str2) << endl<< sizeof(str3) << endl; 27 }大小都是4 阅读全文
posted @ 2013-10-16 17:21 demps_c 阅读(131) 评论(0) 推荐(0)
多态

摘要:c++支持多态的方法引用和指针class a{public: virtual void f(){cout f();// 2 (*a3).f();// 2 a* p1 = new a; a* p2 = new b; b* p3 = dynamic_cast (p1); p3->f();//Segmentation fault p3 = dynamic_cast (p2); p3->f();// no problem return p3;}void f2(){ b* p= f1(); p->f();//2 (*p).f();//2}//cast其实是一种编译器指令,大部... 阅读全文
posted @ 2013-10-16 17:06 demps_c 阅读(166) 评论(0) 推荐(0)
虚继承

摘要:26 class a{ 27 public: 28 a(){cout << "a" << endl;} 29 ~a(){cout << "~a" << endl;} 30 }; 45 class x:virtual public a{ 46 public: 47 x(){cout<<"x" << endl;} 48 ~x(){cout<<"~x" << endl;} 49 }; 50 class y:virtual pu 阅读全文
posted @ 2013-10-16 16:33 demps_c 阅读(119) 评论(0) 推荐(0)
实际上

摘要:如果定义一个类class x{};实际上相当于定义了两个构造函数和一个析构函数还有一个操作符函数实际上是这样的class x{ public: x(){...}; x(const x& x){...} ~x(){...} x& operator=(const x& x1){...}}; 阅读全文
posted @ 2013-10-14 19:55 demps_c 阅读(186) 评论(0) 推荐(0)
设计模式2

摘要:应用程序的可复用性可扩充性和可维护性是最优先考虑的工具箱是一个组相关的可复用的类的集合框架是构成一类特定软件的可复用设计的一组相互协调的类一个使用了设计模式的框架比没有使用设计模式的框架更可能获得高层次的设计复用和代码复用设计模式与框架比较1 设计模式比框架更抽象2 设计模式是比框架更小的体系结构元素3 框架比设计模式更加特例化 阅读全文
posted @ 2013-10-10 11:32 demps_c 阅读(104) 评论(0) 推荐(0)
设计模式1

摘要:根据目的准则分为创建型 与对象的创建有关结构型 处理类或对象的组合行为型 对类或对象怎样交互和怎样分配职责进行描述{创建型类模式将对象的部分创建工作延迟到子类(抽象类),而创建型对象模式将它延迟到另一个对象中结构型类模式使用继承机制来组合类,结构型对象模式则描述了对象的组装方式行为型类模式使用继承描述算法和控制流,行为型对象模式则描述一组对象怎样协调完成单个对象所无法完成的任务}根据范围准则类 处理类和子类之间的关系,这些关系通过继承简历是静态的,在编译时刻便确定下来了对象 处理对象间的关系,这些关系在运行时刻是可以变化的,更具动态性聚合和相识聚合是拥有另一个对象,相识仅仅只是知道他们... 阅读全文
posted @ 2013-10-10 10:07 demps_c 阅读(141) 评论(0) 推荐(0)
vector 数组

摘要:void f3(){ 40 vector go[10]; 41 for(int i=0;i < 10;i ++){ 42 for(int j = 1;j < 100;j ++){ 43 go[i].push_back(j); 44 } 45 } 46 for(int i=0;i < 10;i ++){ 47 for(int j = 0;j < 99;j ++){ 48 cout << go[i][j]<<endl; 49 } 50 } 51 } 阅读全文
posted @ 2013-10-09 22:06 demps_c 阅读(151) 评论(0) 推荐(0)
模板元编程

摘要:#include 2 using namespace std; 3 templatestruct factoria{ 4 enum{ val = factoria::val * n};//注意n后面没有;只有union abc{int a;double b;}; 5 }; 6 templatestruct factoria{ 7 enum{val = 1}; 8 }; 9 void f1(){ 10 for(int i =1;i ::val struct fab{ 18 enum{ val = fab::val + fab::val}; 19 ... 阅读全文
posted @ 2013-10-09 14:21 demps_c 阅读(226) 评论(0) 推荐(0)
类的const类型

摘要:类中的const变量必须在构造函数中初始化并且得这样class a{ public: a(int i):value(i){}//唯一正确的初始化方式 a(int i){value = i;}//错误的初始化方式 如果不在构造函数里面初始化,就更错了 void go(){} private: const int value;};class b{ 63 public: 64 b(int i):value(i){} 65 void go(){value ++;} 66 void print()const{cout <... 阅读全文
posted @ 2013-10-08 23:25 demps_c 阅读(313) 评论(0) 推荐(0)
函数返回类型

摘要:class x{};x f1(){ x x1; return x1;}void f2(){}void f3(x& x1){}int main(){ x x2; f1() = x2;//可以,因为返回类型为x类型 f2() = x2;//不行,因为f2返回类型为void f3(f1());//此时编译器会产生一个临时对象来保存f1()的返回值,使他能够传递给f3()} 阅读全文
posted @ 2013-10-08 22:05 demps_c 阅读(221) 评论(0) 推荐(0)
c语言预处理器

摘要:可以不受限制的建立宏并用它来代替值,因为预处理器只做些文本替代,它既没有类型检查概念,也没有类型检查功能,所以预处理器的值替换会产生一些微笑的问题 阅读全文
posted @ 2013-10-08 20:49 demps_c 阅读(133) 评论(0) 推荐(0)
enum 与 union

摘要:class a{ 4 public: 5 a(char i):x(i){type = char_t;} 6 a(int i):y(i){type = int_t;} 7 a(long i):z(i){type = long_t;} 8 // private: 9 enum dog{char_t,int_t,long_t}type; 10 void print(); 11 private: 12 union {char x;int y;long z;};//匿名联合体 1... 阅读全文
posted @ 2013-10-08 17:36 demps_c 阅读(295) 评论(0) 推荐(0)
初始化错误

摘要:class b{ 81 public: 82 b(){ 83 str = new string [100]; 84 for(int i=0;i < 100;i ++){ 85 str[i] = "da"; 86 } 87 } 88 void go(){ 89 for(int i=0;i < 100;i ++){ 90 cout << str[i] << endl; 91 } 92 cout <<"end" << endl; 93... 阅读全文
posted @ 2013-10-07 12:04 demps_c 阅读(199) 评论(0) 推荐(0)
string

摘要:string对象的size() 肯定大于等于capacity()插入和追加insert(),append()替换 replace()string b("china");59 cout << "the string china" <<" size is " << b.size() << " capacity " << b.capacity() << endl;60 b.reserve(100);61 cout << "the 阅读全文
posted @ 2013-10-04 09:48 demps_c 阅读(151) 评论(0) 推荐(0)
用于跟踪代码的宏

摘要:#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; 阅读全文
posted @ 2013-10-03 16:54 demps_c 阅读(136) 评论(0) 推荐(0)
boost第一个进程

摘要: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 .. 阅读全文
posted @ 2013-10-03 16:46 demps_c 阅读(516) 评论(0) 推荐(0)
多进程

摘要:本系统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线程库。就在几年前,用多线程执行程序还是一件非比寻常的事。然而今天互联网应用服务程序普遍使用多线程来提高与多客户链接时的效率;为了达到最大的吞吐量,事务服务器在单独的线程 阅读全文
posted @ 2013-10-03 16:40 demps_c 阅读(376) 评论(0) 推荐(0)
first cppunit program

摘要:编译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 ... 阅读全文
posted @ 2013-10-03 15:57 demps_c 阅读(193) 评论(0) 推荐(0)
类与对象问题

摘要:class x{ x(int i){}};class y{ y(){}};throw x(100); 此时是抛出一个对象的(正确)throw x ; 此时应该错误的throw y();此时是抛出一个对象;正确throw y;此时错误必须有一对双括号 阅读全文
posted @ 2013-10-03 11:42 demps_c 阅读(113) 评论(0) 推荐(0)
auto_ptr智能指针

摘要: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... 阅读全文
posted @ 2013-10-03 10:53 demps_c 阅读(165) 评论(0) 推荐(0)
模板编程

摘要: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;则如果后面给出了参数,就... 阅读全文
posted @ 2013-10-03 10:44 demps_c 阅读(319) 评论(0) 推荐(0)
关于异常

摘要:所有标准异常归根结底都是从exception类派生而来,此类定义在头文件exception中两个主要的派生类为logic_error(报告程序逻辑错误,通过检查代码,能够发现这类错误)和runtime_error(报告运行错误,只有在程序运行时候,这类错误才能被检查到)这两个类的定义在头文件stdexcept中,通过exception::what()函数,可以从对象中得到他所保存的消息一般不要从exception派生类,而是从logic_error或者runtime_error派生自己的类class x{ 4 public: 5 class a{}; 6 class b{... 阅读全文
posted @ 2013-10-03 09:45 demps_c 阅读(178) 评论(0) 推荐(0)
异常

摘要:当抛出一个异常时,可以使用任意类型,(包括内置类型)但通常应当为抛出的异常创建特定的类如果在一个函数内部抛出了异常,或者被这个函数所调用的其他函数抛出了异常,这个函数将会因为抛出异常而退去如果不想因为一个throw而退出函数,可以在函数中试图解决实际产生设计问题得地方设置一个try如果后面的catch捕捉成功(不仅仅是设置了catch)则不会退出此函数只要有catch成功捕捉,系统就认为该异常已经处理了throw导致一系列的事情发生1它将创建程序所抛出的对象的一个拷贝,2然后,实际上,包含throw表达式的对象返回了这个对象,即使该函数原先并未设计为返回这种对象类型匹配一个异常并不要求异常与其 阅读全文
posted @ 2013-10-02 22:48 demps_c 阅读(136) 评论(0) 推荐(0)
setjmp

摘要:头文件是然后一般定义一个全局jmp_buf jmp;第一次setjmp(jmp) 返回值为0第二次setjmp()返回值为longjmp(jmp,value);第二个参数的值value 阅读全文
posted @ 2013-10-02 22:22 demps_c 阅读(130) 评论(0) 推荐(0)
assert

摘要:如果assert里面的值为真,则没有任何反应,如果不为真则a.out: test.cpp:80: int main(): Assertion `i != 999' failed.Aborted显式程序名,行数,函数,哪里失败了然后调用abort可以使用字符数组给string赋值char s[] = "quanguorenming";string str = s; 阅读全文
posted @ 2013-10-02 21:40 demps_c 阅读(173) 评论(0) 推荐(0)
bool

摘要:bool a=true; 6 bool b=false; 7 cout <<( a and b )<< endl; 中间必须得用()要不就是语法错误了 8 cout << (a or b) << endl;中间必须得用()要不就是语法错误了 9 cout <<( not a) << endl;中间必须得用()要不就是语法错误了cout << (a not_eq b) << endl; not_eq也是关键字,最后值位1and 和or 和not都是关键字 int i = 65; 12 int j = 阅读全文
posted @ 2013-10-02 17:48 demps_c 阅读(226) 评论(0) 推荐(0)
register

摘要:不能取地址 //但是在中register int ii =0;int *p = &ii;这样竟然是合法的,你没不能计算地址不能全局不能静态可以做形参 阅读全文
posted @ 2013-10-02 17:27 demps_c 阅读(196) 评论(0) 推荐(0)
奇怪

摘要:int i;wait(&i);在c++中竟然说的是i是引用,并且需要出示化,什么情况啊 阅读全文
posted @ 2013-10-02 17:14 demps_c 阅读(119) 评论(0) 推荐(0)
如果用户定义了函数

摘要:如果用户定义了函数,那么就会掩盖库提供的函数 阅读全文
posted @ 2013-10-02 17:00 demps_c 阅读(125) 评论(0) 推荐(0)
定义,就是为变量分配存储空间

摘要:声明只是告诉这个变量或这个函数在某处可以找到 阅读全文
posted @ 2013-10-02 16:01 demps_c 阅读(180) 评论(0) 推荐(0)

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3