The most basic part of C ++...

Source: Internet
Author: User

The access features of the inherited feature subclass of the parent class.
Public
Protected public protected
Private no access

 

Public protected
Protected
Private no aceess

 

Public Private
Protected private
Private no access

 

Function overloading occurs in a class, and function overwriting occurs between the parent class and the subclass.

 

When a Member is not a static member, the subclass can use a: function () to access the function of A, and the: B member can also. A Indicates the parent class name.

C ++ polymorphism: When the C ++ compiler finds that its parent class is a virtual function during compilation, it will adopt the late binding technology based on the type of the passed object.

To determine which function to call (parent class or subclass ). The premise is to pass the pointer of the subclass: If the subclass has a child class, the Child class does not call the parent class.

 

There is also a pure virtual function: the parent class only defines the operation and does not implement it. The inherited class must implement it.

 

# Include <iostream>
Using namespace STD;
Class animal
{
Public:
Static const int cc = 1;
/* Virtual */void breathe ()
{
Cout <"Animal breath" <Endl;
}
// Virtual void breathe () = 0;
};
Class fish: Public animal
{
Public:
Fish (): A (22)
{
}
Void breathe ()
{
Cout <animal: CC <Endl;
Cout <"fish breathe" <Endl;
}
PRIVATE:
Const int;
};

Void fun (animal * Pan)
{
Pan-> breathe ();
}

Int main ()
{
Fish fi;
Animal * pA;
Pa = & fi;
Fun (PA );
System ("pause ");
Return 0;
}

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.