C + + abstract class Two (basic syntax for abstract classes)

Source: Internet
Author: User
Tags define function function prototype prototype definition

//basic syntax for abstract classes#include <iostream>using namespacestd;/*Description of multi-inheritance The fact that multiple inheritance in the real sense is abandoned by the actual development experience in the multi-inherit engineering development is almost not used multiple inheritance brings more code complexity than it brings convenience multiple inheritance has a disastrous effect on the maintainability of the Code, Any multi-inheritance can be replaced by a single inheritance. Most object-oriented languages do not support multiple inheritance the concept that most object-oriented languages support interfaces The concept of C + + does not have an interface in C + + can use pure virtual function to implement interface class only function prototype definition, no data definition. Summary: The analog interface class in C + + defines 3 conditions 1. Only public access (because subclasses must be required to override parent-class pure virtual functions) 2. You can only define function prototypes and do not provide implementations 3. Cannot define any member properties of the Analog interface class in C + + Features 1. You cannot define an interface class object 2. You can define a pointer and reference 3 for an interface class. The interface class must be pure virtual function, not virtual function pure virtual function and virtual function difference pure virtual function: virtual void P      Rint () = 0;      virtual function: virtual void Print () {cout<< "I am the ordinary virtual function" <<ENDL;} Pure virtual function does not have function implementation, virtual function has practical engineering experience proves that multiple inheritance interfaces do not bring about two semantics and complexity multiple inheritance can be done by carefully designing a single inheritance and interface instead of an interface class is just a function description, not a feature implementation. Subclasses need to define feature implementations based on functional descriptions. */classpoint{ Public:    Virtual voidPrint () =0;};classPointa: Publicpoint{Virtual voidPrint () {cout<<"I'm a subclass. I rewrote the pure virtual function of the parent class"<<Endl; }};voidPROTECTB () {//Point p1; Error C2259: ' point ': cannot instantiate abstract classPoint *P1 =NULL;    Pointa PA; P1= &PA; //Generate polymorphicP1->Print ();}voidMain () {PROTECTB (); System ("Pause");}

C + + abstract class Two (basic syntax for abstract classes)

Related Article

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.