#include <iostream>
using namespace std;
class Animal
{
public:
Animal(int _a) : a(_a) {}
virtual void test() { cout << "父类test函数调用" << endl; }
virtual ~Animal() { cout << "~Animal" << endl; }
protected:
int a;
};
class Mouse : public Animal
{
public:
Mouse(int _b) : Animal(_b) {}
virtual void test() { cout << "子类test函数调用" << endl; }
virtual ~Mouse() { cout << "~Mouse" << endl; }
protected:
int b;
};
void Pause()
{
Mouse m[3] = { Mouse(2), Mouse(2), Mouse(2) };
Animal *Ap = m;
Mouse *Mp = m;
cout << sizeof(Animal) << " " << sizeof(Mouse) << endl;
Ap->test();
Mp->test();
Ap++;
Mp++;
Mp->test();
}
int main()
{
Pause();
system("pause");
return 0;
}