﻿<?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/C++</title><link>http://www.cppblog.com/acmiyou/category/11880.html</link><description>Acmiyou/Sulingr</description><language>zh-cn</language><lastBuildDate>Thu, 24 Sep 2009 16:07:11 GMT</lastBuildDate><pubDate>Thu, 24 Sep 2009 16:07:11 GMT</pubDate><ttl>60</ttl><item><title>C++ 函数重载(overroad) 覆盖(override) 隐藏(hide) 的区别</title><link>http://www.cppblog.com/acmiyou/archive/2009/09/24/97155.html</link><dc:creator>米游</dc:creator><author>米游</author><pubDate>Thu, 24 Sep 2009 11:52:00 GMT</pubDate><guid>http://www.cppblog.com/acmiyou/archive/2009/09/24/97155.html</guid><wfw:comment>http://www.cppblog.com/acmiyou/comments/97155.html</wfw:comment><comments>http://www.cppblog.com/acmiyou/archive/2009/09/24/97155.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/acmiyou/comments/commentRss/97155.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/acmiyou/services/trackbacks/97155.html</trackback:ping><description><![CDATA[
		<p>原文转自 <a href="http://blog.chinaunix.net/u/15921/showart_227111.html" mce_href="http://blog.chinaunix.net/u/15921/showart_227111.html">http://blog.chinaunix.net/u/15921/showart_227111.html</a></p>
		<ul>
				<li>
						<strong>成员函数被重载的特征</strong>
				</li>
		</ul>
		<blockquote>
				<p>（1）相同的范围（在同一个类中）； <br />（2）函数名字相同； <br />（3）参数不同； <br />（4）virtual 关键字可有可无。 </p>
		</blockquote>
		<ul>
				<li>
						<strong>覆盖是指派生类函数覆盖基类函数，特征是</strong>
				</li>
		</ul>
		<blockquote>
				<p>（1）不同的范围（分别位于派生类与基类）； <br />（2）函数名字相同； <br />（3）参数相同； <br />（4）基类函数必须有virtual 关键字。</p>
		</blockquote>
		<ul>
				<li>
						<strong>“隐藏”是指派生类的函数屏蔽了与其同名的基类函数，规则如下</strong>
				</li>
		</ul>
		<blockquote>
				<p>（1）如果派生类的函数与基类的函数同名，但是参数不同。此时，不论有无virtual关键字，基类的函数将被隐藏（注意别与重载混淆）。 <br />（2）如果派生类的函数与基类的函数同名，并且参数也相同，但是基类函数没有virtual 关键字。此时，基类的函数被隐藏（注意别与覆盖混淆）</p>
		</blockquote>
<img src ="http://www.cppblog.com/acmiyou/aggbug/97155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/acmiyou/" target="_blank">米游</a> 2009-09-24 19:52 <a href="http://www.cppblog.com/acmiyou/archive/2009/09/24/97155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Effective C++ 读书笔记 条款一至三</title><link>http://www.cppblog.com/acmiyou/archive/2009/09/23/97039.html</link><dc:creator>米游</dc:creator><author>米游</author><pubDate>Wed, 23 Sep 2009 11:20:00 GMT</pubDate><guid>http://www.cppblog.com/acmiyou/archive/2009/09/23/97039.html</guid><wfw:comment>http://www.cppblog.com/acmiyou/comments/97039.html</wfw:comment><comments>http://www.cppblog.com/acmiyou/archive/2009/09/23/97039.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/acmiyou/comments/commentRss/97039.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/acmiyou/services/trackbacks/97039.html</trackback:ping><description><![CDATA[
		<ul>
				<li>
						<strong>条款一 视C++为一个语言联邦</strong>
				</li>
		</ul>
		<blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
				<p>记住,C++中的四种次语言.. </p>
				<p>1.C. c基础..</p>
				<p>2.Object-Oriented C++ ,c++的主要,class ,类封装,继承,多态等.</p>
				<p>3.Template C++ ..c++里头的泛型编程..模板编程.</p>
				<p>4.STL.  标准模板库..如vector,queue,map等.<br /><br />这个条款所叙述的..应当在次语言变换时候,高效编程守则也需要做出相应的改变策略..</p>
				<p>例子: </p>
				<p>    对内置对象类型而言..使用 值传递 要比 引用传递  来的高效</p>
				<p>    对于自定义类而言, 常引用传递往往更好..(const class&amp; )</p>
				<p>    STL 中而言.其是在C指针之上塑造,因此.值传递 也再次适用..</p>
				<p>
						<font color="#ff0033">谨记: 对于C++高效编程原则应当视情况而定..取决使用C++中的那一部分</font>
				</p>
		</blockquote>
		<ul>
				<li>
						<strong>条款2 尽量使用const enum inline 替换 #define 宏</strong>
				</li>
		</ul>
		<blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
				<p dir="ltr" style="MARGIN-RIGHT: 0px">请记住:<br /><font color="#ff3333">1.对于单纯常量,最好以const对象或enums 替换掉 #define..<br /></font>如:  const double PI = 3.141592653<br />class Test{<br />static const double PI;    //声明式<br /> };const double Test::PI = 3.141592653;  //定义式,在实现文件.<br /><font style="BACKGROUND-COLOR: #ffffff" color="#ff0000"><br />2. 对于形似函数的宏..最好改用 inline 函数的形式 替换.<br />&gt;</font></p>
		</blockquote>
		<ul>
				<li>
						<font color="#000000">
								<strong>条款3 尽可能的使用 const </strong>
						</font>
				</li>
		</ul>
		<p>
				<font color="#000000">
						<font color="#800080">         谨记:</font>
				</font>
		</p>
		<blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
				<p>
						<font color="#ff0000">1.将某些东西声明为const 可帮助编译器侦测错误用法. const 可被施加于任何作用域的对象,函数参数.函数返回类型.成员函数本体.</font>
				</p>
				<p>
						<font color="#000000">如, 在C++里常用的 const 引用传值 就如常 const 指针一样.不以前函数修改其值.这就很好的保护了.参数的值不能被修改.</font>
				</p>
				<p>
						<font color="#000000">如. 定义成const 成员函数,在该成员函数里,是不允许修改成员变量的.因此这样一个接口往往可以启动保护数据的作用.</font>
				</p>
				<p>
						<font color="#000000">const 引用传值时候,只能调用.const 成员函数...</font>
				</p>
				<p>
						<font color="#000000">const 返回值 往往会作为接口时候,使得返回值不允许被外部修改.因此也是非常有用.</font>
				</p>
				<p>
						<font color="#000000">STL 当中的iterator..  const vector&lt;int&gt;::Iterator 表示 int * const   指针常量. </font>
				</p>
				<p>
						<font color="#000000">vector&lt;int&gt;::const_Iterator 即 const int *  常量指针..</font>
				</p>
				<p>
						<font color="#000000">
								<font color="#ff0000">2. 编译器强制实施 bitwise constness. 但使用时候 应注意是概念上的常量</font>.</font>
				</p>
				<p>
						<font color="#000000">mutable 将释放掉这种约束..即.这么定义.   mutable int size;</font>
				</p>
				<p>
						<font color="#000000">其定义的变量允许在const 成员函数中予以修改..</font>
				</p>
				<p>
						<font color="#ff0000">3.当const 和 non-const 成员函数 具有等价实现时候,,令non-const 函数 调用const 函数 可避免重复.</font>
				</p>
				<p>
						<font color="#000000">为什么不const 调用 non-const ..原因在于.const 需要保证不允许修改成员变量. 而调用non-const 成员函数.则存在可能已经修改了成员变量.因此这是一种不正确..</font>
				</p>
				<p>
						<font color="#000000">例子可入下所示:</font>
				</p>
				<p>
						<font color="#000000">
								<font color="#008000">[const_cast&lt;T&amp;&gt;](</font>
								<font color="#ff0000">static_cast&lt;const T&amp;&gt;(*this)</font> .function());   const_cast 视情况而定..如需要返回值去掉const属性则就需要了. static_cast&lt;&gt; 则进行一次强制转换成const 引用..<br /></font>
				</p>
		</blockquote>
<img src ="http://www.cppblog.com/acmiyou/aggbug/97039.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/acmiyou/" target="_blank">米游</a> 2009-09-23 19:20 <a href="http://www.cppblog.com/acmiyou/archive/2009/09/23/97039.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>