#include <iostream>
#include <string>
using namespace std;
class P {
   public:
    int id;
    string name;

   public:
    P() { cout << "wu can p gou zao " << endl; }

    P(int id, string name) {
        cout << "you can p gou zao" << endl;
    }
};

class Person {
   public:
    int id2 = 202;
    int id1 = 201;
    P p;

   public:
    Person() { cout << "person gou zao " << endl; }
    Person(int id2) : p(1, "qiumc") { cout << "person" << endl; }
    Person(int id2, int id1) {}
    Person(const Person& p) { cout << "const copy" << endl; }
};

int main(int argc, char const* argv[]) {

    // 在参数列表中显示调用了自定义类型的属性的构造函数P(int id, string name)
    Person p(100);
    // 对自定义类型的属性,没有进行显示初始化,默认会调用自定义类型属性的的默认构造函数
    Person p2(1, 2);
    return 0;
}

相关文章:

  • 2021-08-30
  • 2022-01-18
  • 2021-08-22
  • 2021-06-22
  • 2022-02-19
  • 2021-10-15
  • 2021-09-16
猜你喜欢
  • 2021-09-22
  • 2022-12-23
  • 2021-09-16
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案