学习虚函数(派生/基类)

时间:2015-04-18 08:01:03

标签: c++ derived-class virtual-functions base-class

我正在学习C ++中的虚函数,特别是在Base / Derived类方面。我现在提到的网站是learncpp.com。

我的问题是关于这一小段代码,其中在Animal类中,构造函数Animal()是从m_strName(它是同一个类中的变量)派生的。这怎么可能?还有,是否有可能从任何类(如果有的话)派生构造函数?

#include <string>
class Animal
{
protected:
    std::string m_strName;

    Animal(std::string strName)
        : m_strName(strName)
    {
    }

public:
    std::string GetName() { return m_strName; }
    const char* Speak() { return "???"; }
};

0 个答案:

没有答案
相关问题