1
votes

I keep receiving a long string of errors when I try to declare a vector in the header. I've looked around for awhile, but can't find a solution.

Here are the errors:

1>Compiling... 1>game.cpp 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071: 'input::vector' : illegal storage class 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2238: unexpected token(s) preceding ';' 1>main.cpp 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071: 'input::vector' : illegal storage class 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2238: unexpected token(s) preceding ';' 1>input.cpp 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071: 'input::vector' : illegal storage class 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\legacyblade\documents\visual studio 2008\projects\fourswords\fourswords\input.h(38) : error C2238: unexpected token(s) preceding ';'

Here is the source code:

#include <vector>
#include <SFML/Graphics.hpp>

#ifndef _input_h
#define _input_h

class input
{
public:
      input();
     void update();

//----input keys----//

    // Directions
    bool upPress;
    bool downPress;
    bool leftPress;
    bool rightPress;

    // Actions
    bool aPress;
    bool bPress;
    bool jumpPress;
    bool shieldPress;

    // Menu
    bool startPress;
    bool screenshotPress;
    bool fullscreenPress;

//------------------//

private:
    extern vector<sf::Keyboard::Key> keyBindings;

};

#endif

It gives me the same error with and without extern, and even if I change the type of thing inside the vector (even int).

Thank you so much for reading. It would be great if anyone could help. I need vectors to do what I'm wanting to do. Don't know why it's giving me such trouble. Any other type of variable in the same spot DOES NOT cause the error. Only vectors.

3

3 Answers

2
votes

Just to add to what's been said, you need the namespace in the declaration because we usually don't want to bloat up header files with "using namespace std". So if you've seen vectors used elsewhere without std:: in front of it, the namespace was probably declared elsewhere.

1
votes

You need to use the namespace for vector. Prefix vector with std::.

Also, extern on a class member semantically doesn't make any sense. Remove it.

std::vector<sf::Keyboard::Key> keyBindings;
0
votes
extern vector<sf::Keyboard::Key> keyBindings;

should be

std::vector<sf::Keyboard::Key> keyBindings;