Examples of C + + abstract class and pure virtual function combat

Source: Internet
Author: User

virtual function and pure virtual function please refer to: http://blog.csdn.net/hackbuteer1/article/details/7558868

#include  <iostream>using namespace std;class Animal{public:     Virtual void eat () =0;    virtual void sleep () = 0;}; Class cat:public animal{public:    void eat ()     {         cout<< "The cat is eating now." <<endl;    }    void sleep ()     {         cout<< "The cat is sleeping now." <<endl;    }};class bear:public animal{public:    void  eat ()     {        cout<< "The bear  is eating now. " <<endl;    }    void sleep ()     {         cout<< "The bear is sleeping now." <<endl;    }};class Panda:public Cat,public Bear{public:     void eat ()     {        cout< < "The panda is eating now." <<endl;    }    void sleep ()     {         cout<< "The panda is sleeping now." <<endl;    }};void show (cat *p) {    cout<< "===== =================== "<<endl;    p->eat ();     p->sleep ();     cout<< "========================" &LT;&LT;ENDL;} Int main (int argc, char *argv[]) {    cat *p;     Cat c;    Panda d;    p=&c;    show (p);     p=&d ;     show (P);     return 0;}

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A5/07/wKioL1m2eJbALSuHAAA0tYuK5kE441.png-wh_500x0-wm_ 3-wmp_4-s_32485604.png "title=" 111.png "alt=" Wkiol1m2ejbalsuhaaa0tyuk5ke441.png-wh_50 "/>

This article is from the "10628473" blog, please be sure to keep this source http://10638473.blog.51cto.com/10628473/1964428

Examples of C + + abstract class and pure virtual function combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.