C ++ syntax

Source: Internet
Author: User

The C ++ syntax is too delicate, so many students cannot understand it well. This article provides a few small examples for readers to think about.

1. inline and virtual

# Include <iostream>

Class

{

Public:

Virtual inline void func ()

{

STD: cout <"A: func" <STD: Endl;

}

};

Class B: public

{

Public:

Virtual inline void func ()

{

STD: cout <"B: func" <STD: Endl;

}

};

Int main (INT argc, char * argv [])

{

A (). func ();

B (). func ();

A * P = new B ();

P-> func ();

Delete P;

}

2. Initialization of built-in global variables, static built-in variables, local built-in variables, register built-in variables, and dynamically allocated built-in Variables

# Include <iostream>

Int;

Int & B () {static int result; return result ;}

Int main (INT argc, char * argv [])

{

Int C;

Register int D;

Int & E = * New int;

STD: cout <A <STD: Endl;

STD: cout <B () <STD: Endl;

// STD: cout <C <STD: Endl;

// STD: cout <D <STD: Endl;

STD: cout <e <STD: Endl;

Delete & E;

}

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.