Jan Maděra Jan Maděra - 4 days ago 8
C++ Question

C++ - Visual Studio - missing type specifier - int assumed

class Space2D {
public:
vector<Agent> v;
bool star;

Space2D() {
bool star = false;
}
};


In visual studio this give me a error: missing type specifier - int assumed. I also get errors like syntax error: missing ';' before '<'.

std::vector<Agent> v;
Solved this

Answer

Three possible problems with this code.

  1. Possibly vector header is not included

Fix: #include <vector>

  1. Possibly Agent class is not defined

Fix: include header, where Agent class is defined

  1. Possibly you forgot to write using namespace std; as wrongly recommended by beginner books

Fix: instead of 'vector' on line 7 use std::vector, or do it wrong and write using namespace std;

Comments