#include<stdio.h>
//初始化列表 提供了对成员变量初始化的方式
//Constructor
class M
{
private:
int mI;
public:
M(int i)
{
printf("M(int i),i=%d\n",i);
mI=i;
}
int getI()
{
return mI;
}
};
class Test
{
private:
const int c; //类里面成员定义时变量不能初始化
M m1;
M m2;
public:
Test():c(1),m1(2),m2(3) //////////////////重要 初始化列表
{ /////const成员只能被初始化 不能被赋值
printf("Test()\n"); ///构造函数体内叫赋值
}
void print()
{
printf("c=%d,m1.mI=%d,m2.mI=%d\n",c,m1.getI(),m2.getI());
}
};
void run()
{
Test t1;
t1.print();
}
int main()
{
run();
printf("Press any key to continue...");
getchar();
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有