0

the below class spits out around 20 errors, but if I comment out the vector bullets it seems to be all fine. Am I missing some obvious error?

#include <vector>
#include "SDL.h"
#include "Bullet.h"

#ifndef GAMEDATA_H
#define GAMEDATA_H

class GameData
{
public:
    GameData();
    ~GameData();
    GameData(const GameData& data);
    GameData& operator=(const GameData* rhs);

    vector<Bullet> bullets;

    SDL_Surface* shipimage;
    SDL_Surface* bulletimage;
};

#endif
1
  • 5
    The responses so far are probably correct, but you need to be specific and include the exact error messages you are getting. It makes a difference most times. Commented Apr 23, 2012 at 17:14

2 Answers 2

7

vector is inside namespace std. Modify you bullets declaration to:

std::vector<Bullet> bullets;
Sign up to request clarification or add additional context in comments.

Comments

2

The vector is declared in namespace std. Change the type to std::vector and all will be fine.

In your source files, if you use std members excessively you might find it useful to declare:

using namespace std;

Before any other code lines. This will allow you to access the std member without the std:: qualifier. This is exactly why you do not see std:: infront of most examples - they declare this directive.

3 Comments

Worth noting that using namespace std; is generally bad way to solve this, as it will pull much more symbols than vector, string etc into global namespace.
I was about to say that exact thing. It's good to tell him why examples usually use it, but not to advise him to use the "using namespace" directive.
I think that using namespace is fine, as long as its scope is restricted. I sometimes use it inside the function scope, where it is just another implementation detail that I can change at any time. I also think that using namespace in (small) source files is fine, because changing it in case of conflicts is still cheap. The real culprit is using namespace in a header file, because this will pollute the global namespace in any file that is including that header.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.