﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-一己薄剑-随笔分类-C++读书笔记</title><link>http://www.cppblog.com/yangjiudan/category/1211.html</link><description>励－厉己力行</description><language>zh-cn</language><lastBuildDate>Sun, 25 May 2008 04:09:12 GMT</lastBuildDate><pubDate>Sun, 25 May 2008 04:09:12 GMT</pubDate><ttl>60</ttl><item><title>C++编程思想学习笔记－命名控制</title><link>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4571.html</link><dc:creator>一己薄剑</dc:creator><author>一己薄剑</author><pubDate>Fri, 24 Mar 2006 14:16:00 GMT</pubDate><guid>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4571.html</guid><wfw:comment>http://www.cppblog.com/yangjiudan/comments/4571.html</wfw:comment><comments>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4571.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/yangjiudan/comments/commentRss/4571.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yangjiudan/services/trackbacks/4571.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: C++												编程思想学习笔记－命名控制																																				一、           																												static																				的使用																						...&nbsp;&nbsp;<a href='http://www.cppblog.com/yangjiudan/archive/2006/03/24/4571.html'>阅读全文</a><img src ="http://www.cppblog.com/yangjiudan/aggbug/4571.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yangjiudan/" target="_blank">一己薄剑</a> 2006-03-24 22:16 <a href="http://www.cppblog.com/yangjiudan/archive/2006/03/24/4571.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++编程思想学习笔记－常量</title><link>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4570.html</link><dc:creator>一己薄剑</dc:creator><author>一己薄剑</author><pubDate>Fri, 24 Mar 2006 14:15:00 GMT</pubDate><guid>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4570.html</guid><wfw:comment>http://www.cppblog.com/yangjiudan/comments/4570.html</wfw:comment><comments>http://www.cppblog.com/yangjiudan/archive/2006/03/24/4570.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/yangjiudan/comments/commentRss/4570.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/yangjiudan/services/trackbacks/4570.html</trackback:ping><description><![CDATA[
		<p>C++编程思想学习笔记－常量</p>
		<p>一、全局范围的const使用<br />1、const的使用有两种效果，一是生成编译期常量，二是运行期常量。<br />      做为编译期常量主要用作值替代，即取代C中的＃define常量定义，一般用于设置数组大小。<br />   此时不分配存储空间，只在有extern限定或取地址时才会分配空间。<br />      做为运行期常量主要控制程序的安全性，它们会被分配空间，但一经初始化就不能再改变，<br />   数组，结构等集合始终是运行期常量，不能当做编译期常量使用，例如不能用于设置数组大小。<br />   另外C中的const只是运行期常量。<br />2、const对指针的使用<br />   指向const的指针 const int* x，int const* x；<br />   const指针 int* const x；<br />   注意：关于赋值，不能把const指针（引用）赋给非const指针（引用）（会通过非const指针改<br />   变const指针指向的值！），但可以把非const指针（引用）赋给const指针（引用）。这是基于<br />   安全的考虑。<br />3、const用于函数参数与返回值<br />       参数做为const值一般作为函数中的一个初始值；但一般如下使用更易理解：<br />  void f(int ic)<br />  {<br />   const int&amp; i=ic;<br />   //others<br />  }<br />    参数做为const指针或引用是基于安全与效率的原因；并且一般不改变参数的函数，参数要用<br /> const int* cip或const int&amp; ci;这样的函数可const和非const参数，若函数参数没有const<br /> 修饰则只能接受非const参数，不能接受const参数，不具有通用性，所以记住如下用法：<br />     void f(const int&amp; ic)<br />     {}<br /> 注意：所有临时变量都是常量；<br />        返回值做为const值时表明此返回值不能做为左值或修改，一般用于用户自定义类，对于内部<br />    数据无意义。<br />        返回值做为const指针时要注意接受返回值的变量要为const所修饰。<br />二、类内部的const使用<br />1、类内部const的含义－它在每个类对象里分配存储空间，且一旦初始化后就不能改变（运行期常<br />   量），它要在构造函数的初始化表中初始化。<br />2、要想在类内部使用编译期常量，可以使用enum枚举；它不会占用存储空间。<br />3、const用于成员函数－表明此类函数不会改变对象的数据，能被const对象所调用（const对象只<br />   能调用const成员函数）但若想在const成员函数中改变数据，有两种方法：<br />   1&gt;通过this指针把const变量强制转换为非const的。<br />   2&gt;用mutable修饰要改变的变量。<br />   推荐使用2&gt;。<br />三、volatile的使用<br />   表示此数据可以被改变－－用于编译器对此数据的优化假定，当编译器读取此数据时会认为它已<br />   被改变会再次读取到寄存器中，不会假定它没变从而直接使用寄存器的值。<br />   const volatile表示这个对象不能被程序员改变，但可以通过外面的工具改变（？不懂）。</p>
<img src ="http://www.cppblog.com/yangjiudan/aggbug/4570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/yangjiudan/" target="_blank">一己薄剑</a> 2006-03-24 22:15 <a href="http://www.cppblog.com/yangjiudan/archive/2006/03/24/4570.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>