The application methods of C ++ programming language are flexible. You can select the appropriate application methods based on your own needs to complete various functions. Today we will introduce some practical operations of the C ++ custom class, hoping to help you.
- //// // TestClass. h ///////////////////
- Class TestClass
- {
- Public:
- Void Test ();
- Int;
- Private:
- Int B;
- Public:
- Static int c;
- // Do not forget to include this Semicolon. Otherwise, the following cpp will prompt the error message indicating that the semicolon is missing in namespace.
- /// // C ++ BaseTest. cpp ////////////////////////
- # Include "stdafx. h"
- # Include "TestClass. h"
- # Include <iostream>
- Using namespace std;
- TestClass tc;
- // Tc. a = 10;
- // Tc. B = 30;
// You will find that an error is reported when initializing TestClass member variables as global variables.
- Int TestClass: c = 8;
// Static variable of the class, which does not need to be added before the definition; otherwise, an error is reported. It is the shared value of all class objects.
- Void TestClass: Test ()
- {
- B = 20;
- Cout <a <"" <B <"" <c <endl;
- }
- Int _ tmain (int argc, _ TCHAR * argv [])
- {
- Tc. a = 10; // The member variables of the class object are correct during local initialization. The member variables of the object belong to the object.
- // For example, you have assigned a value to Member a of the tc object,
In the following Test function, the value of a is a member of the tc of the object.
- Cout <tc. a <endl;
- Tc. Test ();
- While (true)
- {
- }
- Return 0;
- }
The specific operation methods of the C ++ custom class are described here.