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

2019-03-07 08:59发布

问题:

I am getting this error while building a software (ns3) using waf

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

I searched for the error and the solutions say that probably I am missing a using namespace std or #include <set> in my C++ code, but my code is not missing those. The file where the error originates [mp-tcp-typedefs.h] is here (Line 151 has the error).

I tried resolving the error but still, I Am getting those for a long time now.

My gcc/g++ version is g++ (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7.

回答1:

You should not put using namespace std; in a header file:

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

You can probably fix your code by moving your using namespace std; inside your own namespace changing this:

using namespace std;

namespace ns3 {

to this:

namespace ns3 {

using namespace std;

But better to remove the using namespace std; and qualify all your standard symbols with std:: or else declare them individually inside your own namespace.

namespace ns3 {

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