c++ - [over.load]/1 下面突出显示的句子是什么意思?

标签 c++ overloading language-lawyer using-directives name-lookup

下面突出显示的句子是什么意思?跟函数模板有关系吗?

[over.load]/1 :

Not all function declarations can be overloaded. Those that cannot be overloaded are specified here. A program is ill-formed if it contains two such non-overloadable declarations in the same scope. [ Note: This restriction applies to explicit declarations in a scope, and between such declarations and declarations made through a using-declaration ([namespace.udecl]). It does not apply to sets of functions fabricated as a result of name lookup (e.g., because of using-directives) or overload resolution (e.g., for operator functions). — end note ]

最佳答案

你可以这样做:

namespace N {
  void f(int);
}

namespace M {
  int f(int);
}

using namespace N; // ok
using namespace M; // ok
// even if both have conflicting f's

您并没有直接在此处重载任何内容。 using 指令允许名称查找来查找这两个函数,而此时调用是不明确的。

这里的函数集包含两个不可重载的函数,但由于它们是根据引用通过名称查找找到的,所以它们没问题。

关于c++ - [over.load]/1 下面突出显示的句子是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57042197/

相关文章:

c++ - 覆盖中的几个基本问​​题

C++ signed 和 unsigned int 与 long long 速度

c++ - 未命名类 C++ 中的静态数据成员

C++ 对象 block 分配与单独分配

c++ - 是否可以像这样重载 operator<< ?

java - 为什么下面的代码会出错?为什么重载不成功?

c++ - 对 std::string 使用 operator [] 是否安全

c++ - 通过推导强制引用模板类型

c++ - 我不明白为什么第二个版本的代码片段可以编译。 AFAIK 它不应该,因为 §10.3/2

c++ - 如何正确阅读整个istream?