<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>LinuxSir.cn，穿越时空的Linuxsir! - C\C++</title>
    <link>http://linuxsir.cn/forum.php?mod=forumdisplay&amp;fid=205</link>
    <description>Latest 20 threads of C\C++</description>
    <copyright>Copyright(C) LinuxSir.cn，穿越时空的Linuxsir!</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Wed, 15 Apr 2026 12:07:48 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://linuxsir.cn/static/image/common/logo_88_31.gif</url>
      <title>LinuxSir.cn，穿越时空的Linuxsir!</title>
      <link>http://linuxsir.cn/</link>
    </image>
    <item>
      <title>C++多态和虚函数快速入门教程</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=399016</link>
      <description><![CDATA[在《C++将派生类赋值给基类（向上转型）》一节中讲到，基类的指针也可以指向派生类对象，请看下面的例子：
#include 
using namespace std;
//基类People
class People{
public:
    People(char *name, int age);
    void display();
protected:
    char *m_name;
   ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Wed, 03 Jan 2024 02:57:24 +0000</pubDate>
    </item>
    <item>
      <title>将派生类引用赋值给基类引用</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=399015</link>
      <description><![CDATA[引用在本质上是通过指针的方式实现的，这一点已在《引用在本质上是什么，它和指针到底有什么区别》中进行了讲解，既然基类的指针可以指向派生类的对象，那么我们就有理由推断：基类的引用也可以指向派生类的对象，并且它的表现和指针是类似的。

修改上例中 main() 函数 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Wed, 03 Jan 2024 02:56:44 +0000</pubDate>
    </item>
    <item>
      <title>将派生类指针赋值给基类指针</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=399014</link>
      <description><![CDATA[除了可以将派生类对象赋值给基类对象（对象变量之间的赋值），还可以将派生类指针赋值给基类指针（对象指针之间的赋值）。我们先来看一个多继承的例子，继承关系为：

下面的代码实现了这种继承关系：
#include 
using namespace std;
//基类A
class A{
public:
    A(i ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Wed, 03 Jan 2024 02:56:07 +0000</pubDate>
    </item>
    <item>
      <title>C++将派生类赋值给基类（向上转型）</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=399013</link>
      <description><![CDATA[在 C/C++ 中经常会发生数据类型的转换，例如将 int 类型的数据赋值给 float 类型的变量时，编译器会先把 int 类型的数据转换为 float 类型再赋值；反过来，float 类型的数据在经过类型转换后也可以赋值给 int 类型的变量。

数据类型转换的前提是，编译器知道如何对数据 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Wed, 03 Jan 2024 02:55:08 +0000</pubDate>
    </item>
    <item>
      <title>C++虚继承时的构造函数</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=399012</link>
      <description><![CDATA[在虚继承中，虚基类是由最终的派生类初始化的，换句话说，最终派生类的构造函数必须要调用虚基类的构造函数。对最终的派生类来说，虚基类是间接基类，而不是直接基类。这跟普通继承不同，在普通继承中，派生类构造函数中只能调用直接基类的构造函数，不能调用间接基类的 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Wed, 03 Jan 2024 02:54:27 +0000</pubDate>
    </item>
    <item>
      <title>虚继承（Virtual Inheritance）</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398950</link>
      <description><![CDATA[为了解决多继承时的命名冲突和冗余数据问题，C++ 提出了虚继承，使得在派生类中只保留一份间接基类的成员。

在继承方式前面加上 virtual 关键字就是虚继承，请看下面的例子：
//间接基类A
class A{
protected:
    int m_a;
};
//直接基类B
class B: virtual public A{ ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Tue, 02 Jan 2024 02:22:44 +0000</pubDate>
    </item>
    <item>
      <title>C++虚继承和虚基类详解</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398949</link>
      <description><![CDATA[多继承（Multiple Inheritance）是指从多个直接基类中产生派生类的能力，多继承的派生类继承了所有父类的成员。尽管概念上非常简单，但是多个基类的相互交织可能会带来错综复杂的设计问题，命名冲突就是不可回避的一个。

多继承时很容易产生命名冲突，即使我们很小心地 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Tue, 02 Jan 2024 02:20:56 +0000</pubDate>
    </item>
    <item>
      <title>命名冲突</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398948</link>
      <description><![CDATA[当两个或多个基类中有同名的成员时，如果直接访问该成员，就会产生命名冲突，编译器不知道使用哪个基类的成员。这个时候需要在成员名字前面加上类名和域解析符::，以显式地指明到底使用哪个类的成员，消除二义性。

修改上面的代码，为 BaseA 和 BaseB 类添加 show() 函 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Tue, 02 Jan 2024 02:18:24 +0000</pubDate>
    </item>
    <item>
      <title>C++多继承（多重继承）详解</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398947</link>
      <description><![CDATA[在前面的例子中，派生类都只有一个基类，称为单继承（Single Inheritance）。除此之外，C++也支持多继承（Multiple Inheritance），即一个派生类可以有两个或多个基类。
多继承容易让代码逻辑复杂、思路混乱，一直备受争议，中小型项目中较少使用，后来的 Java、C#、PHP ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Tue, 02 Jan 2024 02:17:51 +0000</pubDate>
    </item>
    <item>
      <title>C++基类和派生类的析构函数</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398946</link>
      <description><![CDATA[和构造函数类似，析构函数也不能被继承。与构造函数不同的是，在派生类的析构函数中不用显式地调用基类的析构函数，因为每个类只有一个析构函数，编译器知道如何选择，无需程序员干涉。

另外析构函数的执行顺序和构造函数的执行顺序也刚好相反：
创建派生类对象时，构 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Tue, 02 Jan 2024 02:17:08 +0000</pubDate>
    </item>
    <item>
      <title>基类构造函数调用规则</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398906</link>
      <description><![CDATA[事实上，通过派生类创建对象时必须要调用基类的构造函数，这是语法规定。换句话说，定义派生类构造函数时最好指明基类构造函数；如果不指明，就调用基类的默认构造函数（不带参数的构造函数）；如果没有默认构造函数，那么编译失败。请看下面的例子：
#include 
using n ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Mon, 01 Jan 2024 07:48:34 +0000</pubDate>
    </item>
    <item>
      <title>构造函数的调用顺序</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398905</link>
      <description><![CDATA[从上面的分析中可以看出，基类构造函数总是被优先调用，这说明创建派生类对象时，会先调用基类构造函数，再调用派生类构造函数，如果继承关系有好几层的话，例如：
A --&gt; B --&gt; C

那么创建 C 类对象时构造函数的执行顺序为：
A类构造函数 --&gt; B类构造函数 --&gt; C类构造 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Mon, 01 Jan 2024 07:48:13 +0000</pubDate>
    </item>
    <item>
      <title>C++基类和派生类的构造函数</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398904</link>
      <description><![CDATA[前面我们说基类的成员函数可以被继承，可以通过派生类的对象访问，但这仅仅指的是普通的成员函数，类的构造函数不能被继承。构造函数不能被继承是有道理的，因为即使继承了，它的名字和派生类的名字也不一样，不能成为派生类的构造函数，当然更不能成为普通的成员函数。 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Mon, 01 Jan 2024 07:47:37 +0000</pubDate>
    </item>
    <item>
      <title>基类成员函数和派生类成员函数不构成重载</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398903</link>
      <description><![CDATA[基类成员和派生类成员的名字一样时会造成遮蔽，这句话对于成员变量很好理解，对于成员函数要引起注意，不管函数的参数如何，只要名字一样就会造成遮蔽。换句话说，基类成员函数和派生类成员函数不会构成重载，如果派生类有同名函数，那么就会遮蔽基类中的所有同名函数， ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Mon, 01 Jan 2024 07:46:43 +0000</pubDate>
    </item>
    <item>
      <title>C++继承时的名字遮蔽问题</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398902</link>
      <description><![CDATA[如果派生类中的成员（包括成员变量和成员函数）和基类中的成员重名，那么就会遮蔽从基类继承过来的成员。所谓遮蔽，就是在派生类中使用该成员（包括在定义派生类时使用，也包括通过派生类对象访问该成员）时，实际上使用的是派生类新增的成员，而不是从基类继承来的。

 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Mon, 01 Jan 2024 07:46:10 +0000</pubDate>
    </item>
    <item>
      <title>C++三种继承方式</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398885</link>
      <description><![CDATA[C++继承的一般语法为：
class 派生类名:［继承方式］ 基类名{
    派生类新增加的成员
};

继承方式限定了基类成员在派生类中的访问权限，包括 public（公有的）、private（私有的）和 protected（受保护的）。此项是可选项，如果不写，默认为 private（成员变量和成员 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Sun, 31 Dec 2023 14:49:33 +0000</pubDate>
    </item>
    <item>
      <title>C++继承和派生简明教程</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398884</link>
      <description><![CDATA[C++ 中的继承是类与类之间的关系，是一个很简单很直观的概念，与现实世界中的继承类似，例如儿子继承父亲的财产。

继承（Inheritance）可以理解为一个类从另一个类获取成员变量和成员函数的过程。例如类 B 继承于类 A，那么 B 就拥有 A 的成员变量和成员函数。

在C++ ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Sun, 31 Dec 2023 14:49:07 +0000</pubDate>
    </item>
    <item>
      <title>C++引用作为函数返回值</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398883</link>
      <description><![CDATA[引用除了可以作为函数形参，还可以作为函数返回值，请看下面的例子：
#include 
using namespace std;
int &amp;plus10(int &amp;r) {
    r += 10;
    return r;
}
int main() {
    int num1 = 10;
    int num2 = plus10(num1);
    cout  ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Sun, 31 Dec 2023 14:48:29 +0000</pubDate>
    </item>
    <item>
      <title>C++引用作为函数参数</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398882</link>
      <description><![CDATA[在定义或声明函数时，我们可以将函数的形参指定为引用的形式，这样在调用函数时就会将实参和形参绑定在一起，让它们都指代同一份数据。如此一来，如果在函数体中修改了形参的数据，那么实参的数据也会被修改，从而拥有“在函数内部影响函数外部数据”的效果。

至于实参 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Sun, 31 Dec 2023 14:47:58 +0000</pubDate>
    </item>
    <item>
      <title>C++引用10分钟入门教程</title>
      <link>http://linuxsir.cn/forum.php?mod=viewthread&amp;tid=398881</link>
      <description><![CDATA[我们知道，参数的传递本质上是一次赋值的过程，赋值就是对内存进行拷贝。所谓内存拷贝，是指将一块内存上的数据复制到另一块内存上。

对于像 char、bool、int、float 等基本类型的数据，它们占用的内存往往只有几个字节，对它们进行内存拷贝非常快速。而数组、结构体、 ...]]></description>
      <category>C\\C++</category>
      <author>一起看海</author>
      <pubDate>Sun, 31 Dec 2023 14:47:25 +0000</pubDate>
    </item>
  </channel>
</rss>