C ++ Study Notes

Source: Internet
Author: User

1. When inheriting the base class, the base class constructor carries Parameters
Subclass Constructor (): base class (parameter), subclass Parameter

2. Function override (occurs between the parent class and the subclass)
Function overload (between classes)

3. type conversion memory matching

4. c ++ polymorphism (some of the virtual sub-classes call the parent class if they do not exist)
 
Pure virtual function -- virtual void breathe () = 0;

5. C ++ initialization for reference and definition (equivalent to variable alias)
Int B = 6;
Int & a = B;

6. header file pre-Compilation
# Ifndef XXX_H
# Define XXX_H
Jjjjj ()
# Endif

7. Single compilation and project Compilation

 

8. To be continued

============= Simple example ============

A. Polymorphism

# Include <iostream> using namespace STD; Class A {public: A () {cout <"constructor ------ A ()" <Endl ;}~ A () {cout <"destructor ------~ A () "<Endl;} void printinfo () {cout <" WYZ ------- a "<Endl ;}}; Class B: Public A {public: B () {cout <"constructor ------ B ()" <Endl ;}~ B () {cout <"destructor ------~ B () "<Endl;} void printinfo () {cout <" WYZ ------- B "<Endl ;}}; Class A1 {public: A1 () {cout <"constructor ------ A1 ()" <Endl;} virtual ~ A1 () {cout <"destructor ------~ A1 () "<Endl;} virtual void printinfo () {cout <" WYZ ------- A1 "<Endl ;}}; class B1: Public A1 {public: b1 () {cout <"constructor ------ B1 ()" <Endl ;}~ B1 () {cout <"destructor ------~ B1 () "<Endl;} void printinfo () {cout <" WYZ ------- B1 "<Endl ;}; int main () {A * A = new B (); // not a polymorphism, A-> printinfo (); cout <Endl; B. printinfo (); Delete A; cout <Endl; A1 * a1 = new B1 (); // A1-> printinfo (); Delete A1; return 0 ;}

Running result:

 

Constructor ------ A () constructor ------ B () wyz ------- A constructor ------ A () constructor ------ B () wyz ------- B destructor ------~ A () constructor ------ A1 () constructor ------ B1 () wyz ------- B1 destructor ------~ B1 () destructor ------~ A1 () destructor ------~ B () destructor ------~ A ()

 

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.