unqualified name in template

This is a discussion on unqualified name in template within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, About Bjarne's statement in section C.13.8.3 Point of Instantiation Binding, I have made some further thinking and coding. ...

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

    unqualified name in template

    Hello everyone,


    About Bjarne's statement in section C.13.8.3 Point of Instantiation Binding, I have made some further thinking and coding. Here are my two questions.

    --------------------
    Nor can an unqualified name used in a template ever be bound to a local name.
    --------------------

    1. Sometimes we use qualified name in template? I have never usage of qualified names in template. Does Bjarne means some code like this, Does such use rare?

    (suppose Foo is a template class)

    Foo<::myType> or Foo<Somenamespace::myType> or Foo<SomeClass::myType>

    2,

    Does Bjarne indicate qualified names used in a template coule be bound to a local name? For example, we define a local namespace, put a struct in the local namespace, then we could use localNameSpace::strctInLocalNameSpace to instantise the template?

    Puesdu code like this.

    Code:
    void f()
    {
    // inside local function f
    namespace localns {
        struct foo;
    };
    vector<localns::foo> vc;
    }

    thanks in advance,
    George

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    1) Yes, qualified names are used a lot in templates. Don't confuse it with using qualified names to instantiate templates. That's nothing to with it.
    Code:
    template <typename T>
    void Foo<T>::bar()
    {
      // Make frobnicate a dependent name so that it is found in the template super class.
      this->frobnicate();
    }
    2) There's no qualified name that can be used to refer to a local name. And refer to what I pointed out about your confusion in point #1.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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


    Just want to clarify one thing, what do you mean using qualified in a template.

    1. Do you mean using qualified name in template (function or class) definition -- as your sample showing below;
    2. Do you mean using qualified name when we use template (i.e. instantiatise) to bind the qualified name to template parameter?
    3. Or both?

    If you mean (1), here is Bjarne's original words,

    --------------------
    Nor can an unqualified name used in a template ever be bound to a local name.
    --------------------

    During template definition, there is no name binding I think. I think Bjarne should mean during template use -- case (2)?

    Quote Originally Posted by CornedBee View Post
    1) Yes, qualified names are used a lot in templates. Don't confuse it with using qualified names to instantiate templates. That's nothing to with it.
    Code:
    template <typename T>
    void Foo<T>::bar()
    {
      // Make frobnicate a dependent name so that it is found in the template super class.
      this->frobnicate();
    }
    2) There's no qualified name that can be used to refer to a local name. And refer to what I pointed out about your confusion in point #1.

    regards,
    Geroge

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    I mean (1) - I thought my example made that obvious.

    Bjarne means template definition. There is name binding there - two-stage name binding, in fact, which is the topic of this thread.

    There is absolutely nothing special about explicit template parameters when instantiating a template.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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


    What do you mean nothing special? Both qualified name and unqualified name can be used to instantise a template?

    Quote Originally Posted by CornedBee View Post
    There is absolutely nothing special about explicit template parameters when instantiating a template.

    regards,
    George

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Nothing special. No special rules. No special effects. It absolutely doesn't matter if you use qualified names or unqualified names, beyond the usual.

    Well, unless you're doing the instantiating inside the definition of a template, in which case those special rules apply.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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


    How could we instantise a template in its definition? I am conrfused. Could you show some pseudo code please?

    Quote Originally Posted by CornedBee View Post
    Well, unless you're doing the instantiating inside the definition of a template, in which case those special rules apply.

    regards,
    George

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Not in "its" definition. In "a" definition. (Not that the other isn't possible as well, as long as it's another instantiation.)

    Code:
    template <typename T> bar()
    {
      // Note: both func and foo are unqualified and dependent.
      foo(func(T()));
    }
    
    template <typename T> void foo(T t) { ... }
    
    template <typename T>
    typename some_meta_function<T>::type func(T t) { ... }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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


    Do you mean in template function bar, when it is instantised, we also instantise foo and func at the same time from template function bar?

    Quote Originally Posted by CornedBee View Post
    Not in "its" definition. In "a" definition. (Not that the other isn't possible as well, as long as it's another instantiation.)

    Code:
    template <typename T> bar()
    {
      // Note: both func and foo are unqualified and dependent.
      foo(func(T()));
    }
    
    template <typename T> void foo(T t) { ... }
    
    template <typename T>
    typename some_meta_function<T>::type func(T t) { ... }

    regards,
    George

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Yes.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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


    Question answered.

    Quote Originally Posted by CornedBee View Post
    Yes.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21