ISO c++禁止声明没有类型的multiset

ISO C++ forbids declaration of ‘multiset’ with no type

本文关键字:类型 multiset c++ 禁止 声明 ISO      更新时间:2023-10-16

我在使用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 <set>,但我的代码并没有缺少这些。错误产生的文件[mp-tcp-typedefs.h]在这里(第151行有错误)。

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

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

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

为什么使用命名空间std;"被认为是不好的做法?

你可以通过移动你的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;