编辑代码

#include <iostream>
#include <string.h>
using namespace std;

enum Sex{Boy,Gril};

class Person{
    public:
    string name;
    int age;
    Sex sex;

    public:
    Person(){
        cout << "Person 的无参构造函数" << endl;
    }
    // Person(string _name,int _age,Sex _sex){
    //     cout << "Person 的有参构造函数被调用!" << endl;
    //     name = _name;
    //     age = _age;
    //     sex = _sex;
    // }
    Person(string _name){
        cout << "Person 的有参构造函数1被调用!" << endl;
        name = _name;
    }

    //初始化列表
    Person(string _name,int _age,Sex _sex):name(_name),age(_age),sex(_sex){

    }
};
void test(){
    Person p1;
    Person p2 =  Person("Json",12,Boy);
    Person p3 = Person("a");
    Person p4("xi",22,Boy);
    cout << p2.name << "\t" << p2.age << "\t" << (Sex)p2.sex << endl;
    cout << p3.name<< endl;

}

int main() {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    test();
	cout << "Hello JSRUN!   \n\n         - from C++ ." << endl;
	return 0;
}