为:
Derive1's Print() Called.
Derive2's Print() called.
其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。
①定义函数Print()为无值型纯虚函数。请在注释“//**1**”之后添加适当的语句。
②建立类Derivel的构造函数,请在注释“//**2**”之后添加适当的语句。
③完成类Derive2成员函数Print()的定义。请在注释“//**3**”之后添加适当的语句。
④定义类Derivel的对象指针d1,类Derive2的对象指针d2。其初始化值分别为1和2。
源程序文件MyMain2.cpp中的程序清单如下:
//MyMain2. cpp
include <iostream>
using namespace std;
class Base
{
public:
Base(int i)
{
b=i;
}
//* * 1 * *
protected:
int b;
};
class Derivel: public Base
{
public:
//* * 2 * *
void print ()
{
cout<<" Derivel's Print() called."<<end1;
}
};
class Derive2 : public Base
{
public:
Derive2(int i) :Base(i) { }
//* * 3 * *
};
void fun (Base *obj)
{
obj->Print ();
}
int main ( )
{
//* * 4 * *
fun (d1);
fun (d2);
return 0;
}