Global variables are generally defined as follows:
1. Define int Myint in Class 1. cpp;
Then, use extern int Myint in. cpp where you want to use it.
2. Add the following to stdafx. cpp:
Int Myint;
Then add the following to stdafx. h:
Extern int Myint
Variables defined in this way will be visible in any file.
If it is a Class Object:
In stdafx. H, the statement is as follows:
Extern cmyclass g_class;
In stdafx. cpp, define:
Cmyclass g_class;
But there is one thing: extern cmyclass g_class in stdafx. h; the definition of cmyclass or # include cmyclass must be included before this sentence.
3. It is more standardized to define a glbs. h and put the original definitions of all global variables in it. Define an externs. h and add extern to all the variables you previously defined in glbs. h. Note: If you set an initial value in glbs. H, do not add a value to externs. h. The # I nclude <glbs. h> that is called for the first time and the # I nclude <externs. h> that is called later
4. Define variables in the CAPP:
Cstring g_suser; // defines the global
In the class to be referenced:
Extern csvapp theapp; // Add this sentence before the. cpp file constructor.
When referencing: If (theapp. m_susername = ""); // reference it like this.
5. To use a custom global custom class, you can use the following methods in all files.
1. Add the Class header file to stdafx. h.
2. Add the class definition to stdafx. cpp, for example, cmyclass g_class;
3. In the app class of your program, if the header file of the ctestprojectapp class is prefixed with extern cmyclass g_clas