<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
    數據加載中……

    C++中關于繼承的多態

    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論成敗 以架構論英雄 閱讀(368) 評論(0)  編輯  收藏 所屬分類: Reading

    主站蜘蛛池模板: 亚洲精品国产高清嫩草影院| 免费国产成人α片| 最近最新的免费中文字幕| 亚洲欧洲另类春色校园小说| 99久久免费看国产精品| 麻豆亚洲av熟女国产一区二| 最近中文字幕大全免费视频| 亚洲精品午夜视频| 猫咪社区免费资源在线观看 | 亚洲宅男永久在线| 国产成人精品无码免费看| 亚洲视频免费一区| 亚洲欧洲免费无码| 无套内射无矿码免费看黄 | 亚洲福利在线视频| 巨波霸乳在线永久免费视频| 亚洲人成人77777在线播放| 性做久久久久久久免费看| 色欲色欲天天天www亚洲伊| 亚洲国产精品狼友中文久久久| 成在人线AV无码免费| 亚洲AV无码成人网站在线观看| 亚洲国产精品一区二区第一页免| 乱淫片免费影院观看| 亚洲av永久无码精品表情包| 久久成人国产精品免费软件| 亚洲国产欧美国产综合一区 | 免费在线黄色电影| 亚洲午夜视频在线观看| 成年女人看片免费视频播放器| 小说区亚洲自拍另类| 久久久久亚洲AV片无码| 成年男女男精品免费视频网站| 免费国产黄网站在线看| 亚洲男人的天堂在线播放| 日本一区免费电影| 毛片在线播放免费观看| jizzjizz亚洲日本少妇| 亚洲国产精品人久久| 免费二级毛片免费完整视频| 99久久精品免费视频|