代码改变世界

随笔档案-2009年8月15日

C++重载操作符于转换 笔记

2009-08-15 10:46 by htc开发, 169 阅读, 收藏,
摘要: 重载操作符:Overloaded functions that are members of a class may appear to have one less parameter than the number of operands. Operators that are member functions have an implicit this parameter that is bound to the first operand.作为类成员的重载函数,其形参看起来比操作数数目少 1。作为成员函数的操作符有一个隐含的 this 形参,限定为第一个操作数。赋值(=)、下标([])、 阅读全文

C++类的复制控制 笔记

2009-08-15 10:36 by htc开发, 126 阅读, 收藏,
摘要: vector<string> svec;它的初始化过程:编译器首先使用 string 默认构造函数创建一个临时值来初始化 svec,然后使用复制构造函数将临时值复制到svec 的每个元素。The parameter of the copy constructor does not strictly need to be const, but it does need to be a reference. Explain the rationale for this restriction. For example, explain why the following definit 阅读全文

C++类 学习笔记

2009-08-15 10:26 by htc开发, 152 阅读, 收藏,
摘要: 类.Key Concept: Benefits of Data Abstraction andEncapsulation关键概念:数据抽象和封装的好处Data abstraction and encapsulation provide two important advantages:数据抽象和封装提供了两个重要优点:Class internals are protected from inadvertent user-level errors,which might corrupt the state of the object.避免类内部出现无意的、可能破坏对象状态的用户级错误。The c 阅读全文