struct foo
{
string name ;
int id ;
foo(string s, int i):name(s), id(i){} ; // 初始化列表
};
struct Test1
{
Test1() // 无参构造函数
{
cout << "Construct Test1" << endl ;
}
Test1(const Test1& t1) // 拷贝构造函数
{
cout << "Copy constructor for Test1" << endl ;
this->a = t1.a ;
}
Test1& operator = (const Test1& t1) // 赋值运算符
{
cout << "assignment for Test1" << endl ;
this->a = t1.a ;
return *this;
}
int a ;
};
struct Test2
{
Test1 test1 ;
Test2(Test1 &t1)
{
test1 = t1 ;
}
};
Test1 t1 ; Test2 t2(t1) ;
struct Test2
{
Test1 test1 ;
Test2(Test1 &t1):test1(t1){}
}
struct Test1
{
Test1(int a):i(a){}
int i ;
};
struct Test2
{
Test1 test1 ;
Test2(Test1 &t1)
{
test1 = t1 ;
}
};
struct Test2
{
Test1 test1 ;
Test2(Test1 &t1):test1(t1){}
}
struct foo
{
int i ;
int j ;
foo(int x):i(x), j(i){}; // ok, 先初始化i,后初始化j
};
struct foo
{
int i ;
int j ;
foo(int x):j(x), i(j){} // i值未定义
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有