#define _CRT_SECURE_NO_WARNINGS
#include <ioStream>
using namespace std;
class Student
{
private:
int age;
char* name;
public:
Student(){
cout << " 空参数构造函数" << endl;
}
Student(char* name, int age){
this->name = (char*)malloc(sizeof(char)* 100);
strcpy(this->name, name);
this->age = age;
cout << " 2参数 构造函数" << endl;
}
Student(char* name) :Student(name, 0){
cout << " 1参数 构造" << endl;
}
char* getName(){
return this->name;
}
int getAge(){
return this->age;
}
};
void main(){
cout << "hello world" << endl;
Student *stu = new Student("lsw");
cout << stu->getName() << "," << stu->getAge() << endl;
getchar();
}
C++ 构造函数 学习
最新推荐文章于 2024-03-21 21:00:20 发布