Thread: qualified name and unqualified name

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    qualified name and unqualified name

    Hello everyone,


    I have searched web, wikipedia and some books. But can not find a exact definition for what is qualified name and unqualified name. Here is a small part from Bjarne's book, for example.

    I think qualified name means names with namespace qualifier in this context? Unqualified name means no namespace qualifier ahead of a name? Correct or not?

    --------------------
    Not can an unqualified name used in a template ever be bound to a local name. Finally, even if a template is first used within a class, unqualified names used in the template will not be bound to members of that class. Ignoring lcoal names is essential to prevent a lot of nasty macro-like behavior.

    section C.18.3.3 Point of Instantiation Binding
    --------------------


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    I think you mean C.13.8.3, not C.18.3.3.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats, Cool!!


    Then how do you understand "Not can an unqualified name used in a template ever be bound to a local name."? Could you show some pseudo code please?

    BTW: you are correct, I mean C.13.8.3.

    Quote Originally Posted by matsp View Post
    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.

    I think you mean C.13.8.3, not C.18.3.3.

    --
    Mats

    regardsm
    George

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think that's what the sort(vector<T>& v) example is about - it shows that the template takes precedence over the local function.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    1.

    Do you mean this sample?

    Code:
    template <class T> void sort (vector<T>& v)
    {
        sort (v.begin(), v.end());
    }
    2.

    If yes, what do you mean "template takes precedence over the local function"? I can not see a local function called sort?

    Quote Originally Posted by matsp View Post
    I think that's what the sort(vector<T>& v) example is about - it shows that the template takes precedence over the local function.

    --
    Mats

    regards,
    George

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The "local" sort is the one inside class Container:
    Code:
    ...
    public:
      void sort() 
       {
           sort(v);
        }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Mats,


    I think you are not correct. The function sort is a global one, I mean this one,

    Code:
    template <class T> void sort (vector<T>& v)
    the function sort below is a member function of class Container,

    Code:
    public:
    void sort()
    {
        ::sort (v);
    }
    How could the 1st global sort function call the 2nd non-static member function of Container directly as you mentioned before? It at lease needs an object instance in order to call a member function.

    Any comments?

    Quote Originally Posted by matsp View Post
    The "local" sort is the one inside class Container:
    Code:
    ...
    public:
      void sort() 
       {
           sort(v);
        }
    --
    Mats

    regards,
    George

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    class X
    {
        public:
           void fact(int n) { return (n == 1):1:n*fact(n-1); };
    };
    This calls fact() recursively.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Mats,


    Do you mean the public member function of class Container does not call recursively? If yes, I do not know how could recursive call happen even if we remove all template related stuff -- it is basic function parameter matching issue, not template issue, you can see the public member function sort accept empty parameters, but inside the member function, we call sort with parameter vector of type vector<int>, only the global function matches, how could recursive call happen?

    Code:
    public:
      void sort() 
       {
           sort(v);
        }

    Quote Originally Posted by matsp View Post
    Code:
    class X
    {
        public:
           void fact(int n) { return (n == 1):1:n*fact(n-1); };
    };
    This calls fact() recursively.

    --
    Mats

    regards,
    George

Popular pages Recent additions subscribe to a feed