C++ 什么是qualified-id/name 和unqualified-id/name?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7257563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:41:48  来源:igfitidea点击:

What are qualified-id/name and unqualified-id/name?

c++

提问by M3taSpl0it

I was wondering if someone could explain there terms since I encounter them in many places. I know some basic theory about them but not sure what I know is right or wrong.

我想知道是否有人可以解释这些术语,因为我在很多地方都遇到过它们。我知道一些关于它们的基本理论,但不确定我所知道的是对还是错。

So can any one please explain these terms?

那么任何人都可以解释这些术语吗?

采纳答案by Sadique

A qualified name is one that has some sort of indication of where it belongs, e.g. a class specification, namespace specification, etc. An unqualified name is one that isn't qualified.

限定名称是具有某种指示其所属位置的名称,例如类规范、命名空间规范等。非限定名称是未限定的名称。

Read James McNellis' answer here:

在这里阅读 James McNellis 的回答:

What is a nested name specifier?

什么是嵌套名称说明符?

Given:

鉴于:

struct  A {
    struct B {
        void F();
    };
};
  • Ais an unqualified-id.
  • ::Ais a qualified-idbut has no nested-name-specifier.
  • A::Bis a qualified-idand A::is a nested-name-specifier.
  • ::A::Bis a qualified-idand A::is a nested-name-specifier.
  • A::B::Fis a qualified-idand both B::and A::B::are nested-name-specifiers.
  • ::A::B::Fis a qualified-idand both B::and A::B::are nested-name-specifiers.
  • A是一个不合格的 id
  • ::A是一个qualified-id,但没有nested-name-specifier
  • A::B是一个限定 ID并且A::是一个嵌套名称说明符
  • ::A::B是一个限定 ID并且A::是一个嵌套名称说明符
  • A::B::F是一个qualified-idB::并且A::B::都是nested-name-specifiers
  • ::A::B::F是一个qualified-idB::并且A::B::都是nested-name-specifiers


回答by Alok Save

A qualified name is one that specifies a scope.
Consider the following sample program, the references to coutand endlare qualified names:

限定名称是指定范围的名称。
考虑以下示例程序,对cout和的引用endl是限定名称:

#include <iostream>

int main()  
{
   std::cout<<"Hello world!"<<std::endl;
   return 0;
}

Notice that the use of coutand endlbegan with std::. These make them Qualified names.

请注意,使用coutendl开始std::。这些使他们成为合格的名称

If we brought cout and endl into scope by a using declaration or directive*(such as using namespace std;), and used just coutand endljust by themselves , they would have been unqualified names, because they would lack the std::.

如果我们把cout和ENDL到范围通过using声明或指令*(如using namespace std;),只是用来coutendl自己只是,他们本来不合格的名字,因为他们缺乏std::