1 Class Student 2 { 3 Public : 4 /* ******************** ***** */ 5 Student (); // Default constructor. If a constructor with parameters is defined, the default constructor will be overwritten and must be manually defined. Otherwise, the constructor cannot be called. 6 ~ Student (); // Destructor 7 /* Destructor, automatically executed at the end of the object's lifetime 8 1. Execute the destructor of a local object in the out-of-scope. 9 2. Static local object:ProgramExecute at execution end or exit 10 3. Global Object: executed at the end of program execution or exit 11 */ 12 13 Student (Int ID, Char * Name, Int S, group G): Sex (s), group (g ); // Member initialization Constructor 14 15 Student ( Const Student & sother ); // Copy constructor 16 17 Student ( Int ID ); // Conversion constructor: Convert int to student 18 19 Operator Int (); // Type conversion function, which converts student to int 20 21 // If conversion constructor and type conversion function exist at the same time, there may be ambiguity, such: 22 23 Student Operator + ( Const Student & S1 );// + Operator Overloading 24 25 Student Operator = ( Const Student & S1 ); // Value assignment operator overload 26 27 Friend ostream Operator <(Ostream & output, Const Student & S1 ); // Youyuan function, heavy stream insertion operator < 28 29 Friend istream Operator >>( Istream & input, Const Student & S1 ); // Youyuan function, heavy stream extraction operator> 30 31 Void Display () Const ; // A common member function cannot modify data members in a class. 32 33 Static Void Test (); // A static member function cannot access non-static members. It belongs to the entire class. 34 35 Inline Void TT (); // Inline built-in functions. The system automatically declares the member functions defined within the class as built-in functions. 36 37 /* ******************** ***** */ 38 Private : 39 /* ******************** ***** */ 40 Int Sid; 41 Char Sname [ 20 ]; 42 Char * Pname; // Pointer, You need to allocate memory to it in the constructor 43 Static Int Age; // Static data member, which belongs to the entire class and is initialized outside the class 44 45 /* * ******************* Constant members and sub-objects **************** *************** */ 46 // You can only initialize a member through the member initialization list. 47 // Define the object execution sequence: 48 // 1. allocate memory 49 // 2. initialize the member list 50 // 3. Execute the constructor 51 Const Int Sex; // Constant data member, initialized upon definition 52 Group group; // Sub-Object 53 /* * ******************* Constant members and sub-objects **************** *************** */ 54 /* ******************** ***** */ 55 }