zoukankan      html  css  js  c++  java
  • C++在自定义类型中定义其他自定义类型的属性初始化过程

    #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;
    }
  • 相关阅读:
    负载均衡——LVS DR模式
    Java之BigDecimal详解
    Spring AOP代理对象创建流程
    spring aop切面不生效
    aspectj-autoproxy Controller未生效解决方案
    jvm参数分类
    dubbo优雅停机
    Dubbo 协议注意项
    dubbo provider
    查找java_home的安装路径
  • 原文地址:https://www.cnblogs.com/qiumingcheng/p/15522673.html
Copyright © 2011-2022 走看看