<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

    主站蜘蛛池模板: 亚洲国产av无码精品| 国产网站在线免费观看| 九月丁香婷婷亚洲综合色| 中美日韩在线网免费毛片视频 | 嫩草在线视频www免费看| 亚洲第一成人影院| 无码一区二区三区亚洲人妻| 精品剧情v国产在免费线观看 | 免费在线看污视频| 日本红怡院亚洲红怡院最新| 你好老叔电影观看免费| 国产国拍亚洲精品mv在线观看| 最近免费mv在线观看动漫| 成年性羞羞视频免费观看无限| 日韩免费在线视频| 亚洲色大成网站www| 亚洲第一视频网站| 亚洲国产精品久久久久婷婷老年| 亚洲国产精华液网站w| 亚洲欧洲日韩国产综合在线二区| 亚洲a一级免费视频| 亚洲国产精品久久久久久| 久久综合亚洲色一区二区三区 | 亚洲自国产拍揄拍| 综合自拍亚洲综合图不卡区| 亚洲欧洲高清有无| 国产天堂亚洲精品| 亚洲精品第一国产综合精品99 | 特黄特色大片免费| 亚洲va久久久噜噜噜久久男同 | 日本免费一区二区三区最新vr| 国产成人亚洲精品电影| 亚洲综合另类小说色区| 91九色视频无限观看免费| 亚洲日韩亚洲另类激情文学| 亚洲国产精品国产自在在线| 暖暖免费在线中文日本| 亚洲中文字幕AV每天更新| 久久久久亚洲av成人无码电影 | 国产v亚洲v天堂无码网站| 天天影院成人免费观看|