Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误帮助:ISO C++;禁止声明';向量';没有类型_C++_Vector - Fatal编程技术网

C++ 错误帮助:ISO C++;禁止声明';向量';没有类型

C++ 错误帮助:ISO C++;禁止声明';向量';没有类型,c++,vector,C++,Vector,正如标题所述,我不确定为什么会出现这个错误。我已经编写了一个类似于此结构的test.cpp,它运行良好。另外,除了向量问题,还有另一个关于“protected”的问题,它甚至不在代码中。我认为“受保护”是一个宏,所以不知道有什么。我是QT新手,所以我可能“做错了”。这肯定是编译器的建议 In file included from DrvCrystalfontz.cpp:8: LCDText.h:28: error: ISO C++ forbids declaration of 'vector'

正如标题所述,我不确定为什么会出现这个错误。我已经编写了一个类似于此结构的test.cpp,它运行良好。另外,除了向量问题,还有另一个关于“protected”的问题,它甚至不在代码中。我认为“受保护”是一个宏,所以不知道有什么。我是QT新手,所以我可能“做错了”。这肯定是编译器的建议

In file included from DrvCrystalfontz.cpp:8:
LCDText.h:28: error: ISO C++ forbids declaration of 'vector' with no type
LCDText.h:28: error: expected ';' before '<' token
LCDText.h:30: error: ISO C++ forbids declaration of 'vector' with no type
LCDText.h:30: error: expected ',' or '...' before '<' token
LCDText.h:46: error: expected ':' before 'protected'
LCDText.h: In constructor 'LCDText::LCDText(int, int, int, int, int, int, int, QObject*)':
LCDText.h:33: error: expected '{' at end of input
scons: *** [DrvCrystalfontz.o] Error 1
scons: building terminated because of errors.
DrvCrystalfontz.cpp中包含的文件中的
:8:
LCDTEX.H:28:错误:ISO C++禁止声明“vector”,没有类型

LCDText.h:28:错误:应为“;”在“之前,向量驻留在std命名空间中。您必须执行以下操作之一:

在类型前面加上命名空间:

std::vector<std::vector<char *> > chars;

C++标准库中声明的每个符号都是STD命名空间的一部分。为了使用这些声明,您必须以其全名引用它。即std::.
正如MichaelM回答的,您应该使用std::vector而不是vector。 但是,您可以使用以下“使用声明”:
1. <代码>使用std::vector
2. <代码>使用命名空间std;//使用名称空间。。。;大多数情况下都不鼓励这种做法,因为它会导致符号大量导入全局命名空间

在任何情况下,大多数时候都应该避免在头文件中使用声明,因为它会污染头文件中每个用户的全局名称空间


祝你好运

为了人类之爱,请不要在头文件中“使用名称空间XXX”。你会让每一个遇到它的程序员都哭。同意,但你也可以告诉人们选项;)然后包括这个选项:使用std::vector;我更喜欢在include之后立即将其放在.cpp中。把std::放得到处都是,并记录为什么要包含标题(这并不总是像vector那样明显)。如果你把它放在你的类定义中。和任何声明一样,它的作用域是有限的。
std::vector<std::vector<char *> > chars;
using std::vector;
vector<vector<char *> > chars;
using namespace std;