【问题标题】:ISO C++ forbids declaration of ‘multiset’ with no typeISO C++ 禁止声明没有类型的“multiset”
【发布时间】:2015-10-31 03:52:42
【问题描述】:

我在使用 waf 构建软件 (ns3) 时遇到此错误

In file included from ../src/internet-stack/mp-tcp-typedefs.cc:6:
../src/internet-stack/mp-tcp-typedefs.h:151: error: ISO C++ forbids declaration of ‘multiset’ with no type
../src/internet-stack/mp-tcp-typedefs.h:151: error: expected ‘;’ before ‘<’ token
In file included from ../src/internet-stack/mp-tcp-socket-impl.cc:17:
../src/internet-stack/mp-tcp-typedefs.h:151: error: ISO C++ forbids declaration of ‘multiset’ with no type
../src/internet-stack/mp-tcp-typedefs.h:151: error: expected ‘;’ before ‘<’ token

我搜索了错误,解决方案说我的 C++ 代码中可能缺少using namespace std#include &lt;set&gt;,但我的代码没有缺少这些。错误来源[mp-tcp-typedefs.h]的文件是here(第151行有错误)。

我尝试解决错误,但我仍然得到这些错误很长时间了。

我的 gcc/g++ 版本是 g++ (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7。

【问题讨论】:

  • 确保您的 .h 文件中包含 #include &lt;set&gt;
  • @Daniel 是的,.h 文件是我发布的文件,它有#include
  • 请尝试使用std::multiset 以确保这不是名称查找问题的奇怪形式。如果可以,请尝试其他编译器。您当前使用的那个似乎遇到了某种语法误解(可能是由源代码 before 第 151 行中的问题引起的)。另一个编译器可能有更好的诊断。
  • 问题不是由您显示/链接的代码引起的:melpon.org/wandbox/permlink/bj0SKMgUoHoIKrP8 所以它必须由标题引起,或者由标题的组合引起。

标签: c++ compiler-errors ns-3


【解决方案1】:

您不应该将using namespace std; 放在头文件中:

Why is "using namespace std;" considered bad practice?

您可以通过移动您自己的命名空间中的using namespace std; 来修改您的代码:

using namespace std;

namespace ns3 {

到这里:

namespace ns3 {

using namespace std;

但最好删除 using namespace std; 并使用 std:: 限定所有标准符号,或者在您自己的命名空间内单独声明它们

namespace ns3 {

using std::string;
using std::list;
using std::multiset;
using std::queue;

【讨论】:

  • 您能否建议一些读数以便我尝试修复错误?
  • @Fernando 当我进行这些更改时,它修复了我系统上的错误。也许你没看对?你能把你的新代码贴在某个地方让我看看吗?
  • @Fernando 没有好书的替代品。这是一个推荐列表:stackoverflow.com/questions/388242/…
  • 是的,感谢您的指导,但这真的是某种深奥的错误吗?这只是一个语法错误,它无法编译,有什么问题?
  • 停止!改变你的问题,让它呈现complete, minimal testcase
猜你喜欢
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多