C++のサブクラスコンストラクション関数の後にコロンで親クラスコンストラクションメソッドを呼び出す
1769 ワード
C++忘れも悪くないですが、最近ふと忘れてしまうかもしれない使い方を記録してみました.つまり、私のサブクラスのコンストラクション関数が親を呼び出すコンストラクションメソッドは、クラスでコンストラクション関数を定義するときに、後でコロンで親コンストラクション関数の呼び出しを書くことができます.
#include
#include
#include
#include
using namespace std;
class Person{
public: int age;
string name;
//
Person(int a,string s):age(a),name(s){
cout<<"hehe"<class Student:public Person
{
public:
static int ID;
//
Student() : Person(ID,"saaa"){
cout<<" "<int Student::ID=1;
int main()
{
//
Student stu = Student();
cout<