1、| (或运算(有1是1,没1是0)
)
^(异或运算(相同为0,不同为1))
3、primer引用使用说明
^(异或运算(相同为0,不同为1))
2、错误处理
一看到 delete崩溃, 基本上就两种情况:
1. 是野指, 指向的内存已经delete过了,然后又再次delete, 这种问题容易发生在有多个地上对这个内存进行释放的程序中. 2. 访问越界, 准确说是写越界, 破坏了堆内存管理. |
应用关于继承一个重要特征
1、使得能够将特性从一个类传递给另一个类的语言特效被称为继承。
继承的另一个特征,基类引用可以指向派生类对象,而无需进行强制类型转换。这种特征的一个实际结果是,可以定义一个接受基类引用作为参数的函数,调用该函数时,可以将基类对象对象作为参数,也可以将派生类对象作为参数。
例子代码
#include<iostream>
using namespace std;
class Animal
{
public:
float m_fWeight;
float m_fHeight;
int m_nSex;
Animal(float weight,float height,int sex)
{
cout<<"Animal 构造"<<endl;
m_fWeight = weight;
m_fHeight = height;
m_nSex = sex;
}
virtual ~Animal()
{
cout<<"Animal 析构"<<endl;
}
virtual void eat()
{
cout<<"Animal eat"<<endl;
}
virtual void showParameter()
{
cout<<m_fWeight<<"\t"<<m_fHeight<<"\t"<<m_nSex<<"\t"<<endl;
}
};
class Dog : public Animal
{
public:
float m_nSpeed;
Dog(float weight = 0,float height = 0,int sex = 0,float speed = 0):Animal(weight,height,sex)
{
cout<<"Dog 构造"<<endl;
m_nSpeed = speed;
}
~Dog()
{
cout<<"Dog 析构"<<endl;
}
void eat()
{
cout<<"Dog eat"<<endl;
}
};
class Cat : public Animal
{
public:
float m_nSpeed;
Cat(float weight = 0,float height = 0,int sex = 0,float speed = 0):Animal(weight,height,sex)
{
cout<<"Cat 构造"<<endl;
m_nSpeed = speed;
}
~Cat()
{
cout<<"Cat 析构"<<endl;
}
void eat()
{
cout<<"Cat eat"<<endl;
}
void showParameter()
{
cout<<m_fWeight<<"\t"<<m_fHeight<<"\t"<<m_nSex<<"\t"<<m_nSpeed<<endl;
}
};
void toEat(Animal &animal)
{
animal.eat();
animal.showParameter();
}
int main()
{
Dog littleDog;
toEat(littleDog);
Cat littleCat;
toEat(littleCat);
return 0;
}