c++实例研究

从0开始

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  104 随笔 :: 0 文章 :: 20 评论 :: 0 Trackbacks
#include <cstdlib>
#include 
<iostream>
using namespace std;

class Base
{
public:
    
int i;
    
void showi(){cout<<i<<endl;}
}
;

class Derived : public Base
{
public:
    
int j;
    
void showj(){cout<<j<<endl;}
    Derived
& operator=(const Base& other){i = other.i; return *this;}
}
;

int main()
{
    Base b;
    b.i 
= 0;
    Derived d,d2;
    d.i 
= 1;
    d.j 
= 2;
    b 
= d;
    b.showi();
    system(
"PAUSE");
    d2 
= b;
    d2.showi();
    d2.showj();
    system(
"PAUSE");
    
return 0;
}

posted on 2010-06-06 11:24 elprup 阅读(227) 评论(0)  编辑 收藏 引用 所属分类: c++实例