如何理解两个声明的不同之处

How to understand what two declarations are different

我只是有点不明白 [class.member.lookup] 部分的句子“如果 S ( f , B i ) 和 S ( f , C ) 的声明集不同”,除了它们的类型是不同的,比如如果两个声明声明相同的类型但是它们分别声明在不同的范围内,那么,这两个声明是否不同?例如:

#include <iostream>
int main(){
  void func(int);  //#1
  {
      void func(int); //#2
  }
}

那么,#1 和#2 是不同的声明吗?它们具有相同的类型,只是声明不同 scope.If 它们是不同的,国际标准中的引用在哪里说的?

您引用的文字来自 [class.member.lookup],它仅适用于在 class 范围内查找名称(如本节第一句所述)。

您的示例代码中没有 class,因此本节不适用。

该代码将包含在 [basic.link]/9:

Two names that are the same (Clause 6) and that are declared in different scopes shall denote the same variable, function, type, template or namespace if

  • both names have external linkage or else both names have internal linkage and are declared in the same translation unit; and
  • both names refer to members of the same namespace or to members, not by inheritance, of the same class; and
  • when both names denote functions, the parameter-type-lists of the functions are identical; and
  • when both names denote function templates, the signatures (17.5.6.1) are the same.

所有要点都满足:您的两个 func 都有外部链接,它们都是全局命名空间的成员,函数具有相同的参数类型列表,并且它们不是函数模板.