隐式“使用命名空间std”而无需在源代码中编写它
Implicit “using namespace std” without writing it in the source code
我有一个C 代码,该代码使用endl
,vector
,complex
和cout
有时 没有任何名称空间资格。使用GCC 4.9编译时,我会得到这样的错误:
bfm.h:454:4: error: 'complex' does not name a type
complex<double> inner(Fermion_t x,Fermion_t y);
^
在同一文件中,有std::
预选赛的行:
std::complex<Float> dot(Fermion_t x_t, Fermion_t y_t,int sx,int sy);
在整个代码库中,我看到了以下模板专业
-
std::complex<double>
-
std::complex<cFloat>
-
complex<Float>
-
complex<double>
-
complex<T>
-
complex<S>
。
对于常规的Express structs+complex
和classs+complex
,我都没有在代码库或基本库的代码库中找到一些东西。因此,我认为它确实是标准库复合体类型。
各种 heamer 文件中有几个 using namespace std
,但不是全部。
我尝试用GCC 4.9和Clang 3.7编译此代码库。两者都给出了有关缺失类型的类似错误。是否有可能与较旧版本的GCC一起使用?我试图在所有需要的点上插入std::
,但是我的印象是,如果我不能仅编译用于此类型的计算机的源头结帐,我做错了。
您可以使用选择性using...
声明或键入混叠,仅引入您需要的std::
成员。喜欢:
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
啊,是的,也许不是那么明显,所以值得一提。您现在std::endl
吗?好吧,这是一个流操纵器,实际上是一个功能。这意味着人们也可以从其他名称空间中引入当前块函数。
喜欢:
#include <cmath>
#include <cstdlib>
inline void dummy(float x) {
float y=fabs(x); // Na'a.., fabs is imported into std namespace by <cmath>
using std::itoa; // same is itoa, but we'll be using it
char buff[128];
itoa(42, buff, 10); // OK
}
相关文章:
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 在命名空间中定义函数还是限定函数
- C++:对不存在的命名空间使用命名空间指令
- 通过继承类使用来自不同命名空间的运算符
- 使用命名空间时出现多个定义错误
- CUDA内核和数学函数的显式命名空间
- 嵌套的匿名命名空间
- CMakeLists.txt中的命名空间表示法
- 类是C++中的命名空间吗
- 在命名空间中使用全局命名空间中的函数
- 如何使 std::sort 在 std::swap 和我的命名空间的模板化交换之间没有名称冲突?
- '使用命名空间{嵌套在另一个命名空间中的某个命名空间}"
- 是否可以将函数导入命名空间,但不能导出它?
- C++ C++类中的命名空间降级
- 如何使用 soong 命名空间来有条件地编译模块
- 使用 Clang++ 有没有办法将文件作为命名空间等包含?
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 如何通过命名空间调用非静态方法
- 隐式“使用命名空间std”而无需在源代码中编写它