﻿<?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/lshain/category/17207.html</link><description>Beyond this world...</description><language>zh-cn</language><lastBuildDate>Mon, 10 Oct 2011 11:16:59 GMT</lastBuildDate><pubDate>Mon, 10 Oct 2011 11:16:59 GMT</pubDate><ttl>60</ttl><item><title>C++ 学习笔记</title><link>http://www.cppblog.com/lshain/articles/154691.html</link><dc:creator>Lshain</dc:creator><author>Lshain</author><pubDate>Tue, 30 Aug 2011 06:07:00 GMT</pubDate><guid>http://www.cppblog.com/lshain/articles/154691.html</guid><description><![CDATA[<p>1. 应该提供一个默认的构造函数，并使用初始化列表，初始化成员。</p>
<p>2. 对于单形参的构造函数，最好声明为explicit，可以避免编译器试图产生隐式的类类型转换。</p>
<p>3. static成员函数，只能访问类的static成员，且不能被声明为const类型，也不能被声明成virtual函数。</p>
<p>4. 将一个成员声明为mutable，可以在const类型成员函数中修改它的值，即使该成员属于const类型的对象。</p>
<p>5. 派生类只能通过派生类对象访问基类的protected成员，派生类对其基类类型对象的protected成员没有特殊</p>
<p>访问权限。</p>
<p>6. 不应在派生类的构造函数中，为直接基类的成员赋值，同时，在复制构造函数中，应显示的调用基类的复制</p>
<p>构造函数，为基类对象赋值，如果不显示调用，则派生类中的基类成员将是默认值，而其他成员是一个对象的副</p>
<p>本。也即基类部分没有复制。在赋值操作符中，也应显示调用直接基类的复制操作<br />&nbsp;&nbsp;&nbsp; eg: baseClass::operator=();</p>
<p>8. 赋值操作符应避免自身赋值。</p>
<p>9. 析构函数的调用顺序与构造函数相反，先调用派生类的析构函数，再调用基类的析构函数，每个类的析构函</p>
<p>数只负责释放自己类的成员。</p>
<p>10. 虚函数性质可被继承，继承后也为虚函数。</p>
<p>11. 切记，指针调用虚函数，在运行时，具体调用什么版本，要看在发生调用时，指针的类型。<br />&nbsp;&nbsp;&nbsp; eg: 如果在构造函数或析构函数中调用虚函数，则运行的是为构造函数或析构函数自身类型定义的版本。</p>
<p>12. 局部作用域中的函数不会重载全局作用域中的函数，同样，派生类中的成员函数，不会重载基类中的成员函</p>
<p>数。同时，一旦派生类重定义了基类中的某个成员函数，那么基类中的这个成员函数的所有重载版本在派生类中</p>
<p>都不可用。</p>
<p>13. 要使用基类的某个成员函数的所有重载版本，那么派生类要么重定义基类中成员函数的所有重载版本，要么</p>
<p>一个都不定义，但是只想改变一个或几个重载版本岂不是很麻烦，这时在派生类中用using操作符，派生类不用</p>
<p>重定义所继承的每一个基类版本，它可以为重载成员提供 using声明。一个 using 声明只能指定一个名字，不</p>
<p>能指定形参表，因此，为基类成员函数名称而作的 using 声明将该函数的所有重载实例加到派生类的作用域。</p>
<p>将所有名字加入作用域之后，派生类只需要重定义本类型确实必须定义的那些函数，对其他版本可以使用继承的</p>
<p>定义。</p>
<p>14. 确定函数调用遵循以下四个步骤：<br />&nbsp;&nbsp;&nbsp; 1. 首先确定进行函数调用的对象、引用或指针的静态类型。<br />&nbsp;&nbsp;&nbsp; 2. 在该类中查找函数，如果找不到，就在直接基类中查找，如此循着类的继承链往上找，直到找到该函数</p>
<p>或者查找完最后一个类。如果不能在类或其相关基类中找到该名字，则调用是错误的。<br />&nbsp;&nbsp;&nbsp; 3. 一旦找到了该名字，就进行常规类型检查，查看如果给定找到的定义，该函数调用是否合法。<br />&nbsp;&nbsp;&nbsp; 4. 假定函数调用合法，编译器就生成代码。如果函数是虚函数且通过引用或指针调用，则编译器生成代码</p>
<p>以确定根据对象的动态类型运行哪个函数版本，否则，编译器生成代码直接调用函数。<br /></p> <img src ="http://www.cppblog.com/lshain/aggbug/154691.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lshain/" target="_blank">Lshain</a> 2011-08-30 14:07 <a href="http://www.cppblog.com/lshain/articles/154691.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++ vector指针</title><link>http://www.cppblog.com/lshain/articles/149664.html</link><dc:creator>Lshain</dc:creator><author>Lshain</author><pubDate>Tue, 28 Jun 2011 09:11:00 GMT</pubDate><guid>http://www.cppblog.com/lshain/articles/149664.html</guid><wfw:comment>http://www.cppblog.com/lshain/comments/149664.html</wfw:comment><comments>http://www.cppblog.com/lshain/articles/149664.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lshain/comments/commentRss/149664.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lshain/services/trackbacks/149664.html</trackback:ping><description><![CDATA[<p align="left"><span></p>
<p>记录一下，刚学vector ...<br /><br />&nbsp;vector&lt;string&gt; S1(10);<br />&nbsp;/** 一维*/<br />&nbsp;vector&lt;string&gt;* A1 = new vector&lt;string&gt;(10);<br />&nbsp;/** 二维, 写成这样vector&lt;string&gt;** 我还不知道怎么神马意思... */<br />&nbsp;vector&lt;vector&lt;string&gt;*&gt; *A2 = new vector&lt;vector&lt;string&gt;*&gt;(2);<br /><br />&nbsp;S1[0] = "000000000";<br />&nbsp;(*A1)[0] = "11111"; /** 还不理解，A1[0] 和 (*A1)[0], 不过A1[0]编译错误*/<br />&nbsp;(*A2)[0] = &amp;S1;<br />&nbsp;(*A2)[1] = new vector&lt;string&gt;(10);/** 二维 同不理解 A2[1] 和 (*A2)[1]*/</p>
<p>&nbsp;(*((*A2)[1]))[0] = "ttttttttttt";<br /><br /></p>
<p>&nbsp;cout&lt;&lt;(*A1)[0]&lt;&lt;endl;<br />&nbsp;cout&lt;&lt;(*((*A2)[0]))[0]&lt;&lt;endl;<br />&nbsp;cout&lt;&lt;(*((*A2)[1]))[0]&lt;&lt;endl;<br />&nbsp;delete A1;<br />&nbsp;delete (*A2)[1];<br />&nbsp;delete A2;</p>
<p align="left"></span></p><img src ="http://www.cppblog.com/lshain/aggbug/149664.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lshain/" target="_blank">Lshain</a> 2011-06-28 17:11 <a href="http://www.cppblog.com/lshain/articles/149664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>