templates, namespace, and name lookup

Discussion in 'C++' started by Stefan Naewe, Aug 19, 2008.

  1. Stefan Naewe

    Stefan Naewe Guest

    Hi there.

    Given the following code, why is class B::A used at point //2 and not
    class ::A ?
    Does inheriting a class in a namespace put the names of that namespace into
    the "name pool" used for unqualified lookup?
    Where do I find that in the "Holy Standard" ?

    Thanks,
    Stefan

    // -----SNIP-----
    #include <iostream>

    class A
    {
    public:
    void print()
    {
    std::cout << "class ::A" << std::endl;
    }
    };

    namespace B
    {
    class A
    {
    public:
    void print()
    {
    std::cout << "class B::A" << std::endl;
    };
    };
    }

    template <typename T> class C
    {
    public:
    T object;
    };

    class D : public B::A //1
    {
    public:
    void call_print()
    {
    C<A> c; //2
    c.object.print();
    };
    };

    int main()
    {
    D* test = new D;
    test->call_print();
    delete test;
    return 0;
    }
    // -----SNAP-----

    --
    Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    Plain text mails only, please http://www.expita.com/nomime.html
     
    Stefan Naewe, Aug 19, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    5,167
  2. JKop
    Replies:
    3
    Views:
    522
  3. Marcin Kalicinski

    Cross-namespace name lookup

    Marcin Kalicinski, Jul 25, 2005, in forum: C++
    Replies:
    8
    Views:
    280
    Wisdo Tang
    Aug 3, 2005
  4. recover
    Replies:
    2
    Views:
    858
    recover
    Jul 25, 2006
  5. Dilip
    Replies:
    4
    Views:
    359
    Jerry Coffin
    Aug 10, 2006
Loading...

Share This Page