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;
}