Last time I talked about the nmake command of ms to compile multiple cpp files. This time, I want to step by step without the help of makefile.
Pay attention to the following points:
1. # The mechanism of the include command is to copy the content in the. h file to the. cpp file, so you only need to compile the cpp file. The H file is just a foil. Note that the declaration statement in. h must be filled with a semicolon to end the process. Otherwise, an error will be reported in the Compilation Program. You can save the H file and directly add it to the cpp file. However, in each subsequent file, you need to rewrite the declaration of this class or function. This is also the reason for the existence of the H file.
2. You can use the cl-c command to compile a class file. After compiling it into an obj file, you can use the lib command to compile it into a lib file. Then use the link command to connect multiple obj files. The default executable file name is the name of the first obj file in the command.
View my example
++ ++
# Include <iostream>
Class {
Public:
Int;
Int B;
Void say ();
};
++ ++
/**
Class {
Public:
Int;
Int B;
Void say ();
};
*/
# Include "A. h"
Void A: say (){
A = B;
}
++ ++
// # Include <iostream>
# Include "A. h"
Using namespace std;
Int main (){
A;
A. a = 0;
A. B = 9;
A. say ();
Cout <a. a <"" <a. B <endl;
}
Here is a question that I want to emphasize. Many students may not care about the multi-inclusion of # include. In fact, # include is only a replication mechanism. You can directly include the iostream in the H file of A, so you do not need to include it again in main. Maybe many of you don't care about it.