C++ ISO C&x2B+;禁止申报‘;向量&x2019;没有类型

C++ ISO C&x2B+;禁止申报‘;向量&x2019;没有类型,c++,g++,C++,G++,当我编译我的项目时,我得到了tools.h/tools.h的奇怪错误。 字符串和向量类通过std名称空间使用。我只是看不出有什么错误 g++ powerpi.cpp structs.cpp xmlreader.cpp tools.cpp -o powerpi In file included from structs.cpp:5: tools.h:5: error: ISO C++ forbids declaration of ‘vector’ with no type tools.h:5: e

当我编译我的项目时,我得到了tools.h/tools.h的奇怪错误。 字符串和向量类通过std名称空间使用。我只是看不出有什么错误

g++ powerpi.cpp structs.cpp xmlreader.cpp tools.cpp -o powerpi
In file included from structs.cpp:5:
tools.h:5: error: ISO C++ forbids declaration of ‘vector’ with no type
tools.h:5: error: invalid use of ‘::’
tools.h:5: error: expected ‘;’ before ‘<’ token
g++powerpi.cpp structs.cpp xmlreader.cpp tools.cpp-o powerpi
在structs.cpp中包含的文件中:5:
工具:h:5:错误:ISO C++禁止声明“vector”,没有类型
tools.h:5:错误:无效使用“:”
工具。h:5:错误:应为“;”在“添加到标题之前:

#include <vector>
#包括
添加到标题中:

#include <vector>
#包括
在文件“struct.cpp”中,您需要
包括
,以及
包括

当然,因为所有使用“tools.h”的东西都需要这些工具,所以您可能希望将它们放在“tools.h”的顶部,这样您就可以在任何需要的地方包含“tools.h”

在您的文件“struct.cpp”中,您需要
#include
以及
#include


当然,因为所有使用“tools.h”的东西都需要这些工具,所以您可能希望将它们放在“tools.h”的顶部,这样您就可以在任何需要的地方包含“tools.h”

缺少
#包括
。(也许对于
来说也是如此,尽管你似乎在这方面运气不好,没有出错)你永远不应该认为其他东西会为你包含标题。错误消息是关于structs.cpp的,但你发布了tools.cpp…@marglisse不,标题包含在structs.cpp中,但是实际的错误在tools中。如果convert
是一个模板,您应该在标题中有它的定义。缺少
#include
。(也许对于
来说也是如此,尽管你似乎在这方面运气不好,没有出错)你永远不应该认为其他东西会为你包含标题。错误消息是关于structs.cpp的,但你发布了tools.cpp…@marglisse不,标题包含在structs.cpp中,但是实际的错误在tools中。hSince
convert
是一个模板,您应该在标题中有它的定义。谢谢,这很有效。现在我得到了这些错误:
/tmp/ccDocdbk.o:In function
Gpio::toString()':structs.cpp:(.text+0x190):对
std::basic_string Tools::convert(int)
Gpio.cpp
std::string Gpio::toString(){std::string str std::string(“Gpio{name:”)+name+std::string(“;Gpio:”)+Tools::convert(Gpio))+std::string(“}”);return str;}
@toni这是另一个问题,即.cpp中模板的定义。谷歌和/或搜索“模板未定义引用”-你将获得该问题的一百万次引用和三百万次正确答案;-)谢谢你,成功了。现在我得到了这些错误:
/tmp/ccDocdbk.o:In function
Gpio::toString()':structs.cpp:(.text+0x190):对
std::basic_string Tools::convert(int)
Gpio.cpp
std::string Gpio::toString(){std::string str std::string(“Gpio{name:”)+name+std::string(“;Gpio:”)+Tools::convert(Gpio))+std::string(“}”);return str;}
@toni这是另一个问题,即.cpp中模板的定义。谷歌和/或搜索“模板未定义引用”-你将获得该问题的一百万次引用和三百万次正确答案;-)
#include <vector>