CodeLibrary/01_Clion_Cplus_learn_20240419/src/20240605_Template.cpp

78 lines
1.3 KiB
C++
Raw Normal View History

/*
* Function:
* Date: 2024-04-19
* Design by JRNitre
*
* Function:
* *
* *
* */
#include <iostream>
using namespace std;
class person{
private:
int age;
public:
/*
* -
*
* */
person(){
cout << "构造函数" << endl;
}
/*
* -
* */
person(int a){
this->age = a;
}
/*
*
*
*
* 1. const
* 2.
* */
person(const person &p){
this->age = p.age;
}
/*
*
* */
~ person(){
cout << "析构函数" << endl;
}
int getAge(){
return this->age;
}
};
void test_1 (){
// 默认构造函数调用
person p1;
// 有参构造函数
person p2(10);
// 拷贝构造函数
person p3(p2);
}
void test_2 (){
person p4 = person (10);
person p5 = 10;
}
int main (){
// test_1();
test_2();
system("pause");
return 0;
}