jeans chen
we've got them by the balls
摘要: 为什么拷贝构造函数的参数必须是引用?(2011-10-12 17:31:21)转载▼例子:inline Account::Account( const Accout &rhs ): _balance( rhs._balance ){ _name = new char[strlen(rhs._name)+1 ]; strcpy(_name, rhs._name ); // 不能拷贝 rhs._acct_nmbr _acct_nmbr = get_unique_acct_nmbr();}int main(){Account acct2( acct1 );}问题:为什么拷贝构造函数Accou 阅读全文
posted @ 2013-07-30 17:12 jeans chen 阅读(454) 评论(0) 推荐(0)
摘要: 在小书C++中,4.2.2 派生类的构造函数和析构函数的构造规则(103页)在定义派生类对象时,构造函数执行顺序如下:基类的构造函数对象成员的构造函数派生类的构造函数。 阅读全文
posted @ 2013-07-30 16:00 jeans chen 阅读(153) 评论(0) 推荐(0)
摘要: 令operator=返回一个reference to *this 阅读全文
posted @ 2013-07-30 15:40 jeans chen 阅读(143) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2013-07-30 10:31 jeans chen 阅读(168) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2013-07-30 10:27 jeans chen 阅读(161) 评论(0) 推荐(0)
摘要: 速度 #include using namespace std;class TextBlock{private: string text;public: TextBlock(string s) { text = s; } const char& operator[](size_t position) const {return text[position]; } char& operator[](size_t position) {return text[position]; }};int main(){ TextBlock... 阅读全文
posted @ 2013-07-29 16:06 jeans chen 阅读(198) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2013-07-25 16:47 jeans chen 阅读(170) 评论(1) 推荐(0)
摘要: class B{public: explicit B(int x = 0,bool b = true); //default构造函数 };explicit可以阻止用来执行隐式类型转换,但是可以用来进行显式类型转换。void doSomething (B bObject);doSometing(B(28));//使用B的构造函数将int显式转换(cast)为一个B以促成此一调用copy构造函数被用来“以同型对象初始化自我对象”,copy assignment操作符被用来“从另一个同型对象中拷贝其值到自我对象。”声明式(declaration)是告诉编译器某个东西的名称和类型(type... 阅读全文
posted @ 2013-07-25 16:23 jeans chen 阅读(392) 评论(0) 推荐(0)
摘要: 从别处抄来一个代码 mode是:O_WRONLY 以只写方式打开文件而实际上我用的是read操作,所以老是读出-1检查了很久才发现是这个错误:O_WRONLY 以只写方式打开文件 -> O_RDONLY 以只读方式打开文件花了10分钟,唉!抄来的代码必须一句一句的看阿。不能猛地跳过,否则debug就要把这个时间花过来。 阅读全文
posted @ 2013-07-23 17:10 jeans chen 阅读(144) 评论(0) 推荐(0)
摘要: 接受指针的构造函数为explicit构造函数,所以必须使用初始化的直接形式来创建auto_ptr对象:auto_ptr pi = new int(1024);//errorauto_ptr pi(new int(1024));//ok:uses direct initialization 阅读全文
posted @ 2013-07-22 14:10 jeans chen 阅读(142) 评论(0) 推荐(0)