这很奇怪.我在一个类中创建了一个矢量,但不能在另一个类中创建它.他是我所拥有的代表:
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 ';'
我在这里错过了什么?我可以取消注释第二个矢量声明,它编译得很好.
Jus*_*ini 12
尝试:
std::vector<int> otherOrder;
vector是std命名空间的一部分.这意味着无论何时vector在头文件中使用a ,都应包含std::前缀.
您有时可以忘记它的原因是它们中包含一些包含的文件using namespace std;,允许您省略前缀.但是,您应该避免using头文件中的关键字,因为它会污染任何文件的命名空间include.
有关危险的更详细解释using namespace ...,请参阅此主题.
| 归档时间: | 
 | 
| 查看次数: | 4757 次 | 
| 最近记录: |