Sign in to follow this  

compiler rejecting string?

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i dont know why but my compiler seems to be rejection string heres my code
#include "SDL.h"//duh
#include "Tile.h"// so we can hav the tile lists
#include <string.h>
#include <vector.h>// because they are better and more flexible then arrays 
#pragma once
class Map
{
    protected:
     int m_tileHeight;
     int m_tileWidth;//size of the tiles used on this preticular map
     int m_Height; // in tiles
     int m_Width; // in tiles
     public:
         Map(int width, int height, vector<Tile*> tile,int tileheight, int tilewidth,vector<string> szFiles);//intializing all member variables 
         vector<string> m_szFiles;
         Tile *m_tilelist[];
         vector<Tile*> m_tilelistvec;
         vector<vector<int> >  MapOver;
         void SetFiles(vector<string> ok);
         int GetHeight()                                  {return m_Height*m_tileHeight;};
         int GetWidth()                                   {return m_Width*m_tileHeight;};
         void LoadMap(int MapOver[]);//may be used if i decide to load map from a txt file
         void InitImages(vector<string> szFiles, vector<Tile*> tilelist);
         void InitImages(vector<Tile*> tilelist); 
         void InitMap(vector< vector <int> > Map);
         void DrawMap(SDL_Surface *screen,vector< vector<int> > MapOver,int tilelistsize);   
};

i get this error "14 C:\Dev-Cpp\projects\HI\Map.h `string' was not declared in this scope

Share this post


Link to post
Share on other sites
You need to put std:: in front of it, or put a using namespace std; at the top of your file.

I would also recommend using the non .h versions of the include files (#include <vector> and #include <string>).

Share this post


Link to post
Share on other sites
Two things:

1) There is no ".h" at the end of the C++ standard library headers. It should be

#include <string>
#include <vector>

2) string and vector are within the namespace "std". In any of your own header files, it is best to prefix any use of "string" or "vector" with "std::", thus becoming "std::string" or "std::vector". In your own .cpp files, it is usually considered acceptable to add the line "using namespace std;" near the top, so that you don't have to type out "std::" all the time.

Share this post


Link to post
Share on other sites
Additionally, theres no point in adding #pragma once to a source file. #pragma once tells the compiler to only compile this file once. Which it does with source files anyway.

Share this post


Link to post
Share on other sites
#pragma once doesnt work with gcc/mingw(dev-c++'s compiler) you have to youse old fasioned include guards.

#ifndef HEADERSNAME_H__
#define HEADERSNAME_H__

//code here

#endif

Share this post


Link to post
Share on other sites
Hmm i have been under the impression that every version of gcc up to the latest 3.3 didnt support the #pragma preprocessor, I still prefer #ifndef#define#endif for portability though.

Share this post


Link to post
Share on other sites
gcc has always supported #pragma, it being part of the C/C++ standard and all.

Recent versions of gcc support #pragma once, as you can see
here. However, it is considered obsolete.

Share this post


Link to post
Share on other sites

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this