virtual function _ Pure virtual function _ Abstract class __ function

Source: Internet
Author: User
1, as long as the class containing pure virtual function is abstract class, cannot instantiate object;
2, about polymorphism, in short, is to use the pointer of the parent class type to its subclass instance, and then invoke the member function of the actual subclass through the pointer of the parent class.
※ Need and virtual function table combined understanding

Routines:
 #include <iostream> using namespace std;
    Class A//Abstract Classes {public:virtual ~a () {};    virtual void out1 () = 0;
    The subclass implements the virtual void Out2 ()//default implementation, and subclasses can override {cout << "A (out2)" << Endl;
    } void Out3 ()//enforcing {cout << "A (OUT3)" << Endl;

}
};
    Class B:public A {public:b () {};


    ~b () {};
    void Out1 () {cout << "B (OUT1)" << Endl;
    } void Out2 () {cout << "B (out2)" << Endl;
    } void Out3 () {cout << "B (OUT3)" << Endl;


Private:};

    int main () {//a atest;//Compile Error//atest.out1 ();
    A *ab = new B;
    AB->OUT1 ();
    Ab->out2 ();
    AB->OUT3 ();
    cout << "*************" << Endl;
    b *BB = new B;
    BB->OUT1 ();
    Bb->out2 ();


    BB->OUT3 ();
    Delete ab;
    Delete BB;
    System ("pause");
return 0; }


The results of the line:


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.