在vs2015 中c++学习笔记(孙鑫视频2)

//#include<cstdlib>
#include<iostream>
using namespace std;
//父类
class Animal
{
public://访问方式三种:public、private、protected
Animal(int height,int wigth)
{
// cout << "animal construct" << endl;
}
~Animal()
{
// cout << "animal deconstruct" << endl;
}
void eat();
/* {
cout << "animal eat" << endl;
}*/
//protected:则下面的成员只可以子类调用外部,不可以调用
//private:子类都不可以调用
void sleep()
{
cout << "animal sleep" << endl;
}
// virtual void breathe() = 0;//纯虚函数,无具体实现。有名字无内容,让派生类在具体继承的时候再给出定义
virtual void breathe()
    {
cout << "animal breathe" << endl;
}
};
//子类
class Fish :public Animal
{
/*void test()
{
sleep();
breath();
}*///子类调用
public:
Fish():Animal(400,300),a(1)//子类向基类传递参数
{
// cout << "Fish construct" << endl;
}
~Fish() 
{
// cout << "Fish deconstruct" << endl;
}
void breathe()
{
Animal::breathe();//"::"作用率标识符,表示属于哪一类
cout << "fish bubale" << endl;
}
private:
const int a;//定义常量
};
void Animal::eat()//把函数的实现放到了类外面
{
}
void fn(Animal *pan)
{
pan->breathe();
}
//外部函数调用
void main()
{
//Animal an;
//an.eat();
Fish fh;
Animal *pan;
pan = &fh;
fn(pan);
//fh.breathe;
//fh.sleep();
//引用,变量的别名
int a = 6;
int &b = a;//引用
b = 5;


system("pause");
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值