Open VS2015 and create a new VS win32 project. The previous steps are very simple and will not be explained again.
Let’s start directly:
Create a new VC For win32 programs,
add the .cpp file under the source file, usually the main function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Add the .h file (human.h) to the header file, usually the defined class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The .cpp file in the header file contains the constructor of the class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Then the main function under the source file must add the declaration header file of the class, and the header file .cpp must also Add the header file of the class declaration
i Note: The class defined in the header file must be declared in the c file with the same name. The constructor and destructor of the class are either explicitly defined or The declaration to be displayed, even if there is no execution content in these functions, must be written out empty, otherwise the compilation will fail, or the constructor and destructor of the class will not be written, and the class will generate a constructor that does not execute any program by default. And the destructor
Anyway, one thing: as long as the destructor and constructor in the class are defined, they must be declared, and the function can be empty
The following will add multiple files in VS System (that is, there are multiple header files and cpp files), use VS to automatically generate classes,
1. Right-click the project->Add->Class
After entering the class name, h The file and cpp file are automatically filled in, and the constructor, destructor, and header file of the generated class all have
Generated code:
h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
cpp file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
The above is empty, let’s fill in our function in it
2. Put our function in the class
h file to add the function After
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
After adding the function to the cpp file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
3. Add our class containing header file in main
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Running result:
over! ! !
Related articles:
Complete establishment process of www environment for new server
zend studio New project related issues
The above is the detailed content of Detailed steps to create a new complete c++ project in VS2015. For more information, please follow other related articles on the PHP Chinese website!