I've been flopping around with the good old text editor and terminal for a while now. Toying with SDL2 and all. Now I want to make a proper game out of it and so I'm starting completely over. I've tried a couple different IDEs include Eclipse CDT (C Dev Tools) and Code::Blocks.
I've got three files.
using namespace std;
cout << "whee" << endl;
It tells me SDL_Renderer doesn't name a type in GraphicsEngine.h .
It seems like it is trying to build from GraphicsEngine.cpp instead of 2dgame.cpp .
It compiles fine with "g++ 2dgame.cpp -o 2dgame".
The SDL mailing list told me it wasn't an SDL specific issue which seems to be the case. I tried the same thing with string. Here's a clips from the reply, "In general, it's good practice to not include source (.cpp) files from
other source files. Only ever include header (.h) files. Each .cpp
file must be able to be compiled individually."
Eclipse automagically set up the class to be like that. So does Code::Blocks. So I tried changing the source extension to hpp instead. It compiles fine. With a couple of caveats. First is it generates an #include protection in the source file which it only did in the header before. Second, in Eclipse, if I right click an unimplemented method and select "Source > Implement Method" it does it inline in the header instead of in the source file like before. I'm sure there's a plethora of things I've yet to discover.
I've tried other extensions, too. cxx and cc both do the same errors as cpp. Mysteriously, random extensions like cx, ccc, and cplusplus open up GraphicsEngine.h in a text editor and does nothing with the source file. Then if I switch to a regular extension like cpp it has the class definition twice in the header.
It's frustrating to me that the default behavior is broken. I came to try IDEs to make my life easier and more organized.