<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

    主站蜘蛛池模板: 亚洲精品无码专区久久久| 国产又黄又爽又大的免费视频 | 久久久久久噜噜精品免费直播| 亚洲国产精品综合久久久| 亚洲一区爱区精品无码| 日本高清免费不卡视频| 色老头综合免费视频| 亚洲粉嫩美白在线| 国产免费怕怕免费视频观看| 在线看片韩国免费人成视频| 久久精品免费一区二区三区| 夜夜爽妓女8888视频免费观看| 亚洲综合成人婷婷五月网址| 亚洲小说图片视频| 亚洲专区先锋影音| 好男人看视频免费2019中文| 免费人成动漫在线播放r18 | 成人免费无码H在线观看不卡| 精品国产亚洲第一区二区三区 | 一级一片免费视频播放| 久久久久亚洲av无码专区| 亚洲自偷自偷偷色无码中文| www国产亚洲精品久久久日本| 日本免费一区二区三区最新 | 亚洲性色精品一区二区在线| 亚洲大香伊人蕉在人依线| 亚洲色图国产精品| 免费无码又爽又高潮视频 | 亚洲AV成人影视在线观看| 亚洲影视一区二区| 亚洲一区二区三区播放在线| 亚洲人色大成年网站在线观看| 亚洲午夜爱爱香蕉片| 亚洲国产aⅴ综合网| 亚洲午夜激情视频| 亚洲啪啪AV无码片| 久久国产精品亚洲综合| 免费a级毛片18以上观看精品| 国产免费131美女视频| 四虎亚洲国产成人久久精品| 久99精品视频在线观看婷亚洲片国产一区一级在线 |