I recently became aware that I have no idea, in general, how the c / C ++ compiler works. I admit that this began in an attempt to understand the headline, but came to the realization that I lacked how the compilation works.
Take Visual C ++, for example; In the Header Files folder, Resource Files folder, and Source Files folder. Is there any value for separating these folders and what you put in them? For me, these are all source files. Take the snippets of code:
Fragment 1
and
//a1.cpp int b //<--semicolon left out on purpose
and
//main.cpp
Compiler error: "a1.cpp (3): fatal error C1004: unexpected end of file was detected", where I would expect this because there is no #include in the a1.cpp file, where the main method exists, where in the following code fragment
Fragment 2
//a1.h int r=4 //<--semicolon left out on purpose
and
and
//main.cpp
Errors due to the fact that "main.cpp (6): error C2065:" b ": undeclared identifier". If you included a1.cpp, for example,
Fragment 3
//a1.h int r=4 //<--semicolon left out on purpose
and
and
//main.cpp
the compiler complains about "a1.obj: error LNK2005:" int b "(? b @@ 3HA) already defined in main.obj". Both snippets 2 and 3 ignore the fact that int r = 4 does not have a semicolon, since I suspect that it has anything to do with her xxxx.h file. If I delete the a1.cpp file from the project in fragment 1, it will compile fine. Clearly what I expected, this is not what I get. Theres a lot of books and tutorials on how to code in cpp, but not as much as cpp handles files and source code at runtime. What's going on here?
source share