摘要: 1: C++ 不允许让reference 更改指向的对象 int main(){ string value("wangshuai"); string &a = value; cout<<&a<<endl; string minhua("wuawuawua"); a = minhua; cout<<&a<<endl; cout<<value<<endl; cout<<minhua<<endl; return 0;}输出结果:0x22ff0 阅读全文
posted @ 2011-09-07 16:52 王帅901 阅读(443) 评论(0) 推荐(0) 编辑
摘要: 1: 内置类型以外的任何 东西 其初始化责任落在构造函数上 : 确保每个构造函数都将对象的每一个成员初始化。2:不要搞混了 赋值(assignment) 和 初始化(initiallization) assignment 实际做了 先调用default 构造函数 在调用copy构造函数 消耗较高3: 如果成员变量是const 或是 reference 他们只能被初始化 不能被赋值 也即是说 他们只能在成员初始化类表中被初始化4:non-local static 对象的初始化 (1) static 对象: 从被构造出来开始 , 直到main()函数退出 后才被消亡 ... 阅读全文
posted @ 2011-09-07 12:21 王帅901 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 1:P18 页 经过我的实验 void f1(const A * a);和void f2(A const *a);是不同的! 莫非书上有错?2: STL迭代器 天生就是 T *const ptr 如果需要一个 const T* ptr 则需要的是 const_iterator3: 这个表要记一下子 对象成员函数 对/错1、const const 对2、const non-const 错3、non-const const 对4、not-const non-const 对成员函数调用成员函数 成员函数成员函数 对/错5、const const 对6、const non-const 错7、non.. 阅读全文
posted @ 2011-09-07 11:55 王帅901 阅读(187) 评论(0) 推荐(1) 编辑
摘要: 1:const int * ptr 指向常量(read only)的指针 对指针重新赋值可以 对指针指向的内容重新赋值不行int * const ptr 指向的指针常量2: 在类的声明中 声明一个 static const 型成员变量 是可以的 class A{private: static const int num = 5; int Array[num];};这里对于变量 num 不需要 在定义就可以使用但注意这里 只能声明 const型的成员变量对于 static 非const 成员变量class A{private: static int num = 5; int Arra... 阅读全文
posted @ 2011-09-07 11:10 王帅901 阅读(889) 评论(0) 推荐(0) 编辑