VC++


🌎 欢迎大家关注公众号——空中飞马 后续踩坑记录我会上传到公众号

公众号——空中飞马private 子类、外部不可访问
protected 子类可访问 外部不可访问
public 子类、外部可访问

My_Alice

今天的成果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream.h>
//struct Point
class Point
{
public:
//private:
//protected:
int x;
int y;
/* void init()
{
cin>>x>>y;

} */
Point()
{
	x=0;
	y=0;
}
Point(int a,int b)
{
	x=a;
	y=b;
}
~Point()
{
}

void outcry()
{
	cout<<x<<endl<<y<<endl;
}
void outcry(int x,int y)
{
	this->x=x;
	this->y=y;
}

};
void main()
{
Point pt(3,0);

// cout<<pt.x<<endl<<pt.y<<endl;
// cout<<pt.x<<endl;
// pt.init();
pt.outcry( 5,5);
pt.outcry();

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream.h>
class Animal
{
public:
Animal(int shengao,int tizhong)
{
cout<<“I Love Animal”<<endl;
}
~Animal()
{
cout<<“Not Love Animal”<<endl;
}

void eat()
{
	cout<<"eat"<<endl;
}

protected:
void sleep()
{
cout<<“sleep”<<endl;
}
private:
void jog()
{
cout<<“jog”<<endl;
}

};

class fish : public Animal
{
/* void test()
{
sleep();
jog();
}
*/
public:
fish() : Animal(200,100)
{
cout<<“I Love Fish”<<endl;
}
~fish()
{
cout<<“Not Love Fish”<<endl;
}

};
void main()
{
// Animal ann;
// ann.eat();

fish fhh;

// fhh.test();

//先构造父亲
}
结果为:

1
2
3
4
5
I Love Animal
I Love Fish
Not Love Fish
Not Love Animal
Press any key to continue
先构造基类
析构时子类先析构

函数的覆盖:发生在父类与子类之间
函数的重构:一个类之中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值