<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    選擇java 進入自由開放的國度

    隨筆 - 49, 文章 - 3, 評論 - 154, 引用 - 1
    數(shù)據(jù)加載中……

    C++中關于繼承的多態(tài)

    LibMat
    Book
    AudioBook

    Class:LibMat
    class LibMat  
    {
    public:
        LibMat();
        virtual 
    ~LibMat();
        virtual 
    void print() const;
    }
    ;
    // LibMat.cpp: implementation of the LibMat class.
    //
    //////////////////////////////////////////////////////////////////////

    #include 
    "LibMat.h"
    #include 
    <iostream>

    using namespace std;

    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    LibMat::LibMat()
    {
     cout 
    << "LibMat::LibMat() constructor\n";
    }


    LibMat::
    ~LibMat()
    {
      cout 
    << "LibMat :: ~ LibMat() destructor\n";
    }


    void LibMat ::print() const 
    {
      cout 
    << "LibMat::print() -- I am a LibMat object!\n";
    }

    Class:Book
    #include "LibMat.h"
    #include 
    <string>
    using namespace std;

    class Book : public LibMat  
    {
    public:
        Book(
    const string &const string &);
        virtual 
    ~Book();
        virtual 
    void print() const;
        
    const string& title()  const{return _title;};
        
    const string& author() const{return _author;};
    protected:
        string _title;
        string _author;
    }
    ;
    #include "Book.h"
    #include 
    <iostream>
    using namespace std;
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    Book::Book(
    const string &title, const string &author)
    : _title(title), _author(author)
    {
      cout 
    << "Book::Book(" << _title << "" << _author << ") constructor\n";
    }


    Book::
    ~Book()
    {
     cout 
    << "Book:~Book destructor!\n";
    }


    void Book::print() const 
    {
      cout 
    << "Book ::print() -- I am a Book object!\n"
           
    << "My Title is : " << _title << ", My author is : " << _author << endl;
    }
    測試代碼:main.cpp
    #include "AudioBook.h"
    #include 
    <iostream>
    using namespace std;


    void print(const LibMat&);

    void main ()
    {
      
    //LibMat libmat;
      
    //print(libmat);
      
      
    //polymorphism
      
    //Book b("The Castle", "Franz Kafka");
      
    //print(b);

      cout 
    <<"----------------------\n";
      AudioBook a(
    "The Castle""Franz kafka""Hanhongbo");
      print(a);
    }


    void print(const LibMat& mat)
    {
      cout 
    << "in global print():\n";

      mat.print();
    }

    posted on 2006-01-08 20:37 soochow_hhb 以java論成敗 以架構論英雄 閱讀(360) 評論(0)  編輯  收藏 所屬分類: Reading

    主站蜘蛛池模板: 亚洲AV人无码综合在线观看| 无人在线观看免费高清视频| 成人伊人亚洲人综合网站222| 一二三区免费视频| 成人影片麻豆国产影片免费观看 | 亚洲性无码一区二区三区| 久久WWW免费人成一看片| 亚洲欧洲久久精品| 久久久久久免费视频| 色婷五月综激情亚洲综合| 成人免费视频试看120秒| 国产亚洲欧美日韩亚洲中文色| 日本免费福利视频| 人妻仑乱A级毛片免费看| 亚洲性猛交XXXX| 99久久免费看国产精品| 亚洲美女aⅴ久久久91| 久久天天躁狠狠躁夜夜免费观看 | 三年片在线观看免费观看大全中国| 亚洲A∨精品一区二区三区| 黄桃AV无码免费一区二区三区 | 午夜免费啪视频在线观看| 亚洲精品美女在线观看播放| 无码国产精品一区二区免费式直播 | 日韩精品电影一区亚洲| eeuss影院www天堂免费| 亚洲伊人久久大香线蕉苏妲己| 日韩在线免费视频| 日本高清免费中文在线看| 亚洲国产精品无码专区影院| 我们的2018在线观看免费高清| 亚洲AV女人18毛片水真多| 国产AV无码专区亚洲AV男同| 美女视频黄的全免费视频| h视频在线免费观看| 亚洲福利一区二区精品秒拍| 又爽又黄无遮挡高清免费视频| 免费看少妇高潮成人片| 亚洲一区中文字幕在线电影网| 亚洲AV无码成人精品区大在线| 久久一区二区三区免费播放|