75

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?

M3taSpl0it
  • 2,967
  • 6
  • 28
  • 27

2 Answers2

63

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:

What is a nested name specifier?

Given:

struct  A {
    struct B {
        void F();
    };
};
  • A is an unqualified-id.
  • ::A is a qualified-id but has no nested-name-specifier.
  • A::B is a qualified-id and A:: is a nested-name-specifier.
  • ::A::B is a qualified-id and A:: is a nested-name-specifier.
  • A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.
  • ::A::B::F is a qualified-id and both B:: and A::B:: are nested-name-specifiers.

Community
  • 1
  • 1
Sadique
  • 22,572
  • 7
  • 65
  • 91
  • 1
    What about `B` or `F`, are they unqualified, too? And `B::F`? – Rommudoh Aug 31 '11 at 13:44
  • 15
    @oenone: Simple answer: if it contains `::` it is qualified – David Rodríguez - dribeas Aug 31 '11 at 14:01
  • 4
    @David Rodríguez - dribeas: How does one state difference between: Qualified Id and Qualified name? – Alok Save Aug 31 '11 at 14:06
  • 8
    @Als: They are the same thing. The grammar only mentions *qualified-id* (there is no concept of *qualified-name* in the grammar), but the standard mentions *qualified name* a couple of times to refer to *qualified-id* in textual descriptions. – David Rodríguez - dribeas Aug 31 '11 at 14:32
  • @David: But do see 1.6/2: "_X-name_ is a use of an identifier in a context that determines its meaning. (e.g., _class-name_, _typedefname_). _X-id_ is an identifier with no context-dependent meaning (e.g., _qualified-id_).` – MSalters Sep 01 '11 at 08:32
  • Is the difference between `A::B` and `::A::B` that the first one is a qualified name, whereas the second one is a **fully** qualified name? – pooya13 Jan 05 '21 at 17:21
20

A qualified name is one that specifies a scope.
Consider the following sample program, the references to cout and endl are qualified names:

#include <iostream>

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

Notice that the use of cout and endl began with std::. These make them Qualified names.

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

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • 1
    so qualified name and qualified-d is same thing? –  Aug 31 '11 at 13:33
  • 1
    Basically think of it as if there is a scope resolution operator (the ::) then its qualified. – John Humphreys Aug 31 '11 at 13:34
  • @x4d33746153706c306974: If you're not a compiler expert, you can reasonably ignore the difference. (Roughly speaking, a qualified-id is something that looks like it could be a name, e.g. `std::cout` before the compiler figures out that it's the name of the IOstream output object) – MSalters Sep 01 '11 at 08:30