這很奇怪。我在一個類中創建了一個向量,但無法在另一個類中創建它。他是什麼,我有一個表示:C++無法創建矢量
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;
};
我也得到編譯關於向量聲明錯誤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 ';'
我在這裏錯過了什麼?我可以取消註釋掉第二個向量聲明並且編譯好。
這表明,我認爲一些.h文件中已'使用命名空間std;'在它的地方,這通常是一個壞主意。 'using'不應該在頭文件中完成,因爲它會爲任何直接或間接包含該頭文件的.cpp文件調整名稱空間。僅對源文件使用''使用',效果是本地的。 – 2010-07-28 18:09:06