2010年3月22日
摘要: 偶然有这种情况,一个成员函数在逻辑上是const,但它却仍需要改变某个成员的值。对于用户而言,这个函数看似没有改变其对象的状态,然而,它却可能更新了某些用户不能直接访问的细节。这通常被称为逻辑的常量性。例如,Date类可能有一个函数,它应返回一个用户可以用于打印的字符串表示。构造出这种表示可能是一个相对费时的操作,因此,保留一个副本,在重复需要的时候直接返回这个副本,这一做法也就有意义了,除非这个... 阅读全文
posted @ 2010-03-22 20:04 cppfans 阅读(433) 评论(0) 推荐(0) 编辑
摘要: const成员函数getI()调用非const成员函数f(),编译不通过。 阅读全文
posted @ 2010-03-22 19:51 cppfans 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 2. [8] Write a program that asks the user to enter a list of strings on separate lines,printing each string in a right-justified, 20-character column. To be certain that the output is in the proper co... 阅读全文
posted @ 2010-03-22 15:37 cppfans 阅读(85) 评论(0) 推荐(0) 编辑
摘要: //s1 and s2 have same type, they're both strings that are const const string s1; string const s2; //cstr1, cstr2 and cstr3 are the same type, they're all const pointers to string string s; typedef st... 阅读全文
posted @ 2010-03-22 14:02 cppfans 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 从VS粘贴的代码示例:粘贴代码结束。 阅读全文
posted @ 2010-03-22 10:28 cppfans 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 下面是示例代码 示例代码结束 阅读全文
posted @ 2010-03-22 10:09 cppfans 阅读(70) 评论(0) 推荐(0) 编辑