This is weird. I created a vector just fine in one class but can’t create it in another class. He’s a representation of what I have:
main.h
#include <Windows.h>
#include <ShellAPI.h>
#include <vector>
#include <string>
#include <iostream>
#include "taco.h"
class MyClass
{
public:
int someint;
vector<int> myOrder;
};
taco.h
#include <vector>
class OtherClass
{
public:
vector<int> otherOrder;
};
And I get compile errors regarding the vector declaration in taco.h:
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 ';'
What am I missing here? I can uncomment out that second vector declaration and it compiles fine.
Try:
vectoris part of thestdnamespace. This means that whenever you use avectorin a header file, you should include thestd::prefix.The reason that you can sometimes get away with forgetting it is that some included files may have
using namespace std;in them, allowing you to leave off the prefix. However, you should avoid theusingkeyword in header files, for it will pollute the namespace of any files thatincludeit.For a more detailed explanation of the dangers of
using namespace ..., see this thread.