如何将单个函数引入当前命名空间
How do I bring a single function into the current namespace?
假设我想在名称空间A
中使用std::max
函数。我该怎么做?
namespace A {
void fun()
{
double x = std::max(5.0, 1.0); // I don't want to have to write the std::
}
void fun()
{
using namespace std;
double x = max(5.0, 1.0); // I don't want to have to use the using directive to introduce the entire namespace
}
}
有办法做到这一点吗?
您可以通过在using
声明中命名来"导入"单个符号:
namespace A
{
using std::max;
这意味着A::max
被定义并指定与std::max
相同的功能;因此尝试在CCD_ 7中查找CCD_。
(这是Brandon对原始帖子评论的答案版本)
相关文章:
- 在命名空间中定义函数还是限定函数
- CUDA内核和数学函数的显式命名空间
- 在命名空间中使用全局命名空间中的函数
- 是否可以将函数导入命名空间,但不能导出它?
- 使用另一个命名空间中的函数C++
- Visual Studio 无法解决类和命名空间中重载的明确函数
- 命名空间更改函数定义
- C++命名空间中调用 void 函数的错误
- C++ 17 个友元函数声明和内联命名空间
- MFC 函数来自 :: 命名空间?
- 使用类指针重载C++命名空间函数模板专用化替代方法?
- 在头文件中添加命名空间函数
- 命名空间函数的多重定义
- 在多个 cpp 文件中重用未命名的命名空间函数
- 如何正确声明命名空间函数
- 使用 libclang 解析命名空间函数
- C++命名空间函数
- 内联命名空间函数时出错
- 递归std::functional与递归匿名命名空间函数.使用哪一个
- 如何在命名空间函数中使用pragma weak