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

    主站蜘蛛池模板: 成人免费在线视频| 成全高清在线观看免费| 嫩草影院在线免费观看| 亚洲导航深夜福利| 全免费毛片在线播放| 亚洲第一香蕉视频| 114一级毛片免费| 亚洲 暴爽 AV人人爽日日碰| 噼里啪啦电影在线观看免费高清 | 337p日本欧洲亚洲大胆色噜噜| 七色永久性tv网站免费看| 久久国产精品亚洲综合| 久久不见久久见免费视频7| 亚洲黄色一级毛片| 五月婷婷综合免费| 亚洲色大网站WWW永久网站| 国产传媒在线观看视频免费观看 | 婷婷精品国产亚洲AV麻豆不片| 日本一道本不卡免费| 亚洲综合激情另类小说区| 福利免费观看午夜体检区| 亚洲av中文无码字幕色不卡| 免费成人黄色大片| 亚洲免费观看视频| 亚洲av永久综合在线观看尤物| 国产又大又粗又硬又长免费| 一级女性全黄生活片免费看| 91久久亚洲国产成人精品性色 | 日本牲交大片免费观看| 免费一级全黄少妇性色生活片| 亚洲中文字幕无码中文字在线| 无码国产精品一区二区免费式芒果| 亚洲国色天香视频| 亚洲AV无码专区日韩| 日韩视频免费在线观看| 亚洲第一区二区快射影院| 国产精品亚洲mnbav网站 | 3344免费播放观看视频| 国产产在线精品亚洲AAVV| 亚洲国产精久久久久久久| 一个人免费高清在线观看|