这很奇怪。我在一个类中创建了一个向量,但无法在另一个类中创建它。他是什么,我有一个表示: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