At the end of the lesson Alex states:
"Note that Date.cpp also needs to be compiled into any project that uses Date.h so the linker knows how Date is implemented."
But he doesn't say how to ensure this takes place. Could anyone explain to me how that works? Or is it as simple as the compiler includes any .cpp file that is in the same folder as your main program .cpp?
You need to add the files wich a supposed to be compiled to the project (if you use an IDE) or makefile. They are not automatically included in the build process.
OK! When you say "add", i presume you mean literally use the command "add" in my IDE? (i'm in VS2015).
But that still leaves me a little confused. Because by doing that, all i have done is create a .cpp that lives in the same directory as my other solution files. Which makes me assume that the compiler will include any .cpp that is in that folder.
But you say that is not the case. So if (for the sake of argument) i just copy / paste another .cpp to that folder, that wouldn't be included? If not, then where is this list of .cpp files to be included?
If what i just wrote is totally nonsensical, appologies!
You said: "Only files that are listed in the projects are compiled."
Where can i find / view that list? It's listed in the window on the left of VS2015, is that what you mean? But still i'd like to know, where is it actually listed (in which file)?!
Somewhere in the menu, there is an option to create a new class, when you do that both the header file and the cpp file will automagically be added to your project.
I like to use *.hpp for headers, it means that they contain c++ code, whereas .h may imply C code.
But still i'd like to know, where is it actually listed (in which file)?!
There should be a pane to turn on, that has all of your source, headers targets etc - I have an idea it's on by default, and should be on the left of your screen.
the tree that vs shows you in "Solution Explorer" of your files looks like folders, but they aren't. they are filters. right click one and look at its properties, you will see the file extensions that vs will include in that filter.
to reuse files in another vs project,
1. use windows explorer to copy the files into the new projects folders so they sit with the new projects source code.
2. in "solution explorer" right click the project and choose "Add/Existing Item" and select both .h and cpp files, and click the Add button.
if vs is configured correctly the .h file should appear in the "Header Files" filter, and the cpp should appear in the "Source Files" filter.
if vs is not configured correctly you can drag/drop them into the filter you wish without affecting where the files re actually stored.