#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
using namespace std;
//构造函数调用(有参数构造函数和无参数构造函数)
class TEST
{
public :
TEST()
{
cout<<"调用了无参数构造函数"<<endl;
}
TEST(int a)
{
cout<<"调用了一个参数的构造函数"<<endl;
}
TEST(int a,int b)
{
cout<<"调用了两个参数的构造函数"<<endl;
}
TEST(const TEST& a)
{
cout<<"调用了赋值参数的构造函数"<<endl;
}
private:
protected:
};
int main()
{
TEST t1;//调用无参数构造函数的方法
//调用有参数函数的三个办法
TEST t2(1);
TEST t3=(1,2);//c++对=功能的加强
TEST t4=TEST(1,2);//直接调用构造函数
t1=t4;//对象的赋值 copy
system("pause");
return 0;
}
c++学习记录_03.03
最新推荐文章于 2024-04-18 21:50:03 发布