Martin Ueding Martin Ueding - 1 year ago 80
C++ Question

Implicit “using namespace std” without writing it in the source code

I have a C++ code that uses

, and
occasionally without any namespace qualification. When compiling with GCC 4.9, I get errors like this one:

bfm.h:454:4: error: 'complex' does not name a type
complex<double> inner(Fermion_t x,Fermion_t y);

In the very same file, there are lines with an

std::complex<Float> dot(Fermion_t x_t, Fermion_t y_t,int sx,int sy);

Throughout the codebase, I saw the following template specializations used

  • std::complex<double>

  • std::complex<cFloat>

  • complex<Float>

  • complex<double>

  • complex<T>

  • complex<S>

Neither for the regular express
I managed to find something in the codebase or the codebase of the base library. Therefore I assume that it indeed is the standard library complex type.

There are a couple of
using namespace std
scattered around in various header files, but not all of them.

I tried compiling this codebase with GCC 4.9 and Clang 3.7. Both give similar errors about the missing type. Is there some possibility that this has worked with an older version of GCC? I have tried to insert
at all the needed points but I have the impression that I do something wrong if I cannot just compile the source checkout that is meant for this type of computer.

Answer Source

you can use selective using... declarations or type aliasing to bring in only the std:: members you need. Like:

using std::complex; 
using std::cout;
using std::endl;

cout << "Hello world" << endl; // works
complex<float> x; // works

fstream y; // compile error, no namespace qualification, no using declaration
std::fstream z; // OK
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download