2

At the top of my file main.h I have:

#include <vector>

class Blah
{
  public:
    Blah(){}
    ~Blah(){}
  protected:
    vector<int> someVector;
  public:
    //methods
};

When I try to compile, the vector declaration line gives the errors:

error C2143: syntax error : missing ';' before '<'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2238: unexpected token(s) preceding ';'

I can't figure out what's causing this. Anybody see what I'm doing wrong?

xcdemon05
  • 678
  • 3
  • 7
  • 20
  • `error: no template named 'vector'; did you mean 'std::vector'?` ... I'm *quickly* warming up to the error messages clang produces... – Drew Dormann Apr 04 '13 at 01:47

4 Answers4

10

The vector class is part of the std namespace. You need to replace your declaration with std::vector<int> instead.

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
5

It's in the std namespace:

std::vector<int> someVector;

Pubby
  • 51,882
  • 13
  • 139
  • 180
3

vector is part of the std namespace and so you need to add std:: to your declaration:

std::vector<int> someVector;

Since the suggestion was made in another answers, I want to also discourage the use of using namespace std since it is considered bad practice

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
0

Instead of using,

std::vector someVector;

Always try to use,

using namespace std;

Because it will help you not to type 'std::' again and again, and it is not considered a good practice.

Jigyasu Dhingra
  • 171
  • 1
  • 4