-
tabstop,
Thats a good point. I took a look at cmath and it leads to more include files. There was some implementation in the cmath file, actually a lot. I followed the included files which lead to more code and more included files. So how does this eventually lead to pre-compiled objects and libraries?
-
I have gcc 3.4.5 (at least here on this Windows machine), so maybe there's differences: in my cmath file, I have a lot of "code" that changes the name back to the old-style C names (so asin may go to asin, or asinf, or asinl -- actually with the _builtin__ prefix), but neither c++config.h, cmath.tcc, cpp_type_traits.h, or math.h had any source for any of those functions.
The compiled source for all of those is in libm.a in your lib subdirectory (and if you #include <cmath>, you need to compile with -lm at the end on *nix -- there's a reasonably well-known bug in gcc about that).
-
Here's the deal:
my_class.h contains the class definition, and does not under any circumstances include any .cpp file. C/C++ doesn't work that way.
my_class.cpp should include my_class.h.
Every other source file that uses my_class should include my_class.h.
No file should include my_class.cpp whatsoever.
You compile all source files.
You link all object files.
Or you just use a proper IDE that does all this for you.
You should never include a .cpp file because they contain function definitions and class implementations, so if you include the same .cpp file twice somewhere, you get linking errors.
The fact that you can include vector and just use it is because it's located in a library somewhere and you tell the linker to link against that library.
-
I suggest that you do not take <vector> as an example. The <vector> standard header is for the std::vector class template. The rules for templates can be a little different from normal (e.g., Elysia's dictum that one should "not under any circumstances include any .cpp file" does not necessarily apply as one may include the source file with a class template's implementation into its header file).