构造函数中显式的调基类构造函数
来源:互联网 发布:mysql 查询语句图书 编辑:程序博客网 时间:2024/04/30 05:21
class A
{
public:
A(){i = 3;}
A(int ivl){i = ivl;}
protected:
int i;
};
class B : public A
{
public:
B(int a, int b, int c):A(a), j(b), k(c){}
B(int b, int c)
{
//A();
//A(10);
//A(30);
//只是执行函数,不对B的对象数据成员赋值,因为在进入B的构造函数代码的时候
//对象已经建立,i的值为3,若改值
//i = 10;
j = b;
k = c;
}
void show()
{
cout << "i = " << i << endl
<< "j = " << j << endl
<< "k = " << k << endl;
}
private:
int j;
int k;
};
int main()
{
B b(6, 8);
b.show();
return 0;
}
{
public:
A(){i = 3;}
A(int ivl){i = ivl;}
protected:
int i;
};
class B : public A
{
public:
B(int a, int b, int c):A(a), j(b), k(c){}
B(int b, int c)
{
//A();
//A(10);
//A(30);
//只是执行函数,不对B的对象数据成员赋值,因为在进入B的构造函数代码的时候
//对象已经建立,i的值为3,若改值
//i = 10;
j = b;
k = c;
}
void show()
{
cout << "i = " << i << endl
<< "j = " << j << endl
<< "k = " << k << endl;
}
private:
int j;
int k;
};
int main()
{
B b(6, 8);
b.show();
return 0;
}
- 构造函数中显式的调基类构造函数
- 构造函数的构造顺序
- 构造函数、拷贝构造函数的运用
- 类的构造函数、拷贝构造函数
- String的构造函数拷贝构造函数
- 【构造函数】解析构造函数的作用
- WebService的构造函数
- 类的构造函数
- private的构造函数
- C#的构造函数
- 类的构造函数
- 构造函数 的protected
- 构造函数的理解
- 类的构造函数
- 构造函数的作用
- 构造函数的点点滴滴
- 构造函数的问题
- 类的构造函数
- 中国软件业并购,在何时
- 用最平实的语言撰写你的文章
- 强类型ComboBox的实现方案
- OSGI学习笔记
- 双子天蝎,爱情是不老的传说
- 构造函数中显式的调基类构造函数
- Web文件的ContentType类型大全
- Openlaszlo里集成FusionChart的研究
- 点击左边frame里的链接在右边的frame里打开
- 写了几个WPF和msbuild入门的例子
- 温标发展过程
- MessageBox产生信息窗口在所有窗口最顶端的办法!
- 你信任你身旁的人吗?
- 中国车牌号的识别[全](转)