-3

So I've created a mini personal library containing a bunch of files which have a bunch of methods relating to a specific topic (e.g. string manipulation, math, time, etc.). This is what the, for the lack of a better term, main container file looks like:

#include <iostream>
#include <fstream>
#include <conio.h> //_getch() ("Pauses" the program)
#include <stdlib.h> //atoi (Converts string to integer)
#include <io.h>
#include <stdio.h>
#include <vector>
#include <string> //I have also tried including cstring and string.h, but that didn't help
#include <sstream>
#include <windows.h>
#include <ctime>
#include <math.h>
#include <cmath>
#include <algorithm>

#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"

#include "numbers.cpp"
#include "strings.cpp"
#include "time.cpp"
#include "SDL.cpp"
#include "console.cpp"
#include "files.cpp"

In case anyone's unable to tell, all of the files I made is everything below and including numbers.cpp. The rest are C++ libraries or the 2 SDL files in the middle.

std::string works in all of the files up to console.cpp. There any std::string, whether it be an argument, variable of function declaration, gives me the 'string is not a member of std' error. If I exclude console.cpp from my build targets and project, files.cpp has the same error whenever I try to use std::string. But if I put SDL.cpp, for example, after console.cpp and before files.cpp, its std::strings work fine.

None of the files have any #include in them except SDL.cpp, which only includes some header files which also don't have any include files

I guess it might be important that I do have the following in my compiler linker options:

-lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf

I also have a search directory to the SDL2 include folder, but I don't think that that is the issue. The build type is Static Library (That may be the problem, but it also has the same issues when I build as GUI application, dynamic library or native. I don't know much about build types, fairly new to C++) and I'm using the Code Blocks IDE.

I've already searched for a solution in other similar questions, but all those just forgot to either include string or put it in the wrong place... Thanks in advance for your help, and apologies for the lengthy question and if I've left out any important information.

Christian Hackl
  • 27,051
  • 3
  • 32
  • 62
Gnago
  • 27
  • 7
  • 6
    Why are you including `.cpp` files? – ForceBru Apr 02 '17 at 18:15
  • Do you have a namespace in one of your cpp files (time.cpp?) that isn't closed? – 1201ProgramAlarm Apr 02 '17 at 18:17
  • 1
    [Why should I not include cpp files and instead use a header?](http://stackoverflow.com/questions/1686204/why-should-i-not-include-cpp-files-and-instead-use-a-header) Compiling and linking cpp files may solve your problem or give you a better error message from which you can proceed, but other than that, your question is unanswerable in its current state. Fix up the includes and come back with an edit and more information. – user4581301 Apr 02 '17 at 18:25
  • Never include cpp files in another file. If you want to include a user-created file it should be called "xyz.h" not "xyz.cpp". Compile your cpp files separately and give each one "#include "myheaders.h". Then the order you add the cpp files won't matter. – Jason Lang Apr 02 '17 at 18:30
  • Oh okay, I didn't realize that including .cpp files were bad. Thank you all for the help :) – Gnago Apr 02 '17 at 18:32
  • I've rolled back the edit, because you should not edit your question to include the answer in it. If you know the answer, then post an **answer**. – Christian Hackl Apr 02 '17 at 18:42

1 Answers1

0

Solved - Problem was because I was including .cpp files. Changing them to header files made it work.

Gnago
  • 27
  • 7