cpp_copy_constructor_super - ShenYj/ShenYj.github.io GitHub Wiki

调用父类的拷贝构造函数

class Person {
    int m_age;
public:
    Person(int age) :m_age(age) { }
    Person(const Person &person) :m_age(person.m_age) { }
};

class Student: public Person {
    int m_score;
public:
    Student(int age, int score) :Person(age), m_score(score) { }
    /// 通过调用父类的拷贝构造函数,完成 m_age 的初始化
    Student(const Student &student) :Person(student), m_score(student.m_score) { }
};
⚠️ **GitHub.com Fallback** ⚠️