/* 基类和派生类关系示例,
回答关联问题:
面向对象有哪几个基本特征?前面几章,我们讨论了其中哪几个特征?并解释。
掌握以下知识点:
1.掌握什么是多态?
2.多态分类:编译时多态和运行时多态。在C++中,二者是通过什么来实现的?
*/
/* 本例讲基类与派生类对象间兼容关系 */
#include<iostream>
using namespace std;
/*-------声明基类Base--------- */
class Base{
public:
int i;
Base(int x){ i=x; }
void show()
{ cout<<" Base "<<i<<endl; }
};
/*-----声明公有派生类Derived-----*/
class Derived:public Base{
public:
int y;
Derived(int x,int y1):Base(x){y=y1; }
void show()
{ cout<<" Base, i="<<i<<" derive, y=
回答关联问题:
面向对象有哪几个基本特征?前面几章,我们讨论了其中哪几个特征?并解释。
掌握以下知识点:
1.掌握什么是多态?
2.多态分类:编译时多态和运行时多态。在C++中,二者是通过什么来实现的?
*/
/* 本例讲基类与派生类对象间兼容关系 */
#include<iostream>
using namespace std;
/*-------声明基类Base--------- */
class Base{
public:
int i;
Base(int x){ i=x; }
void show()
{ cout<<" Base "<<i<<endl; }
};
/*-----声明公有派生类Derived-----*/
class Derived:public Base{
public:
int y;
Derived(int x,int y1):Base(x){y=y1; }
void show()
{ cout<<" Base, i="<<i<<" derive, y=