摘要:
根据目的准则分为创建型 与对象的创建有关结构型 处理类或对象的组合行为型 对类或对象怎样交互和怎样分配职责进行描述{创建型类模式将对象的部分创建工作延迟到子类(抽象类),而创建型对象模式将它延迟到另一个对象中结构型类模式使用继承机制来组合类,结构型对象模式则描述了对象的组装方式行为型类模式使用继承描述算法和控制流,行为型对象模式则描述一组对象怎样协调完成单个对象所无法完成的任务}根据范围准则类 处理类和子类之间的关系,这些关系通过继承简历是静态的,在编译时刻便确定下来了对象 处理对象间的关系,这些关系在运行时刻是可以变化的,更具动态性聚合和相识聚合是拥有另一个对象,相识仅仅只是知道他们... 阅读全文
摘要:
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 } 阅读全文
摘要:
#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 ... 阅读全文
摘要:
类中的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 <... 阅读全文
摘要:
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()} 阅读全文
摘要:
可以不受限制的建立宏并用它来代替值,因为预处理器只做些文本替代,它既没有类型检查概念,也没有类型检查功能,所以预处理器的值替换会产生一些微笑的问题 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 阅读全文
摘要:
#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; 阅读全文