467,133 Members | 1,150 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,133 developers. It's quick & easy.

templates, namespace, and name lookup

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 Tclass C
{
public:
T object;
};

class D : public B::A //1
{
public:
void call_print()
{
C<Ac; //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
Aug 19 '08 #1
  • viewed: 1256
Share:
2 Replies
On 8/19/2008 12:18 PM, Stefan Naewe wrote:
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
Anyone?
// -----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 Tclass C
{
public:
T object;
};

class D : public B::A //1
{
public:
void call_print()
{
C<Ac; //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
Aug 20 '08 #2
Stefan Naewe wrote:
On 8/19/2008 12:18 PM, Stefan Naewe wrote:
>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

Anyone?
Well, B::A is a base class of D, so it is "obviously" visible inside
class D's functions. Therefore there is no need to go looking for any
global As elsewhere.

If I could quote chapter and verse, I would have replied with that the
first time. :-)

It is probably a combination of several rules, including "class name
injection" and other nasties.
Bo Persson

>
>// -----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 Tclass C
{
public:
T object;
};

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

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


Aug 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fritz Bosch | last post: by
2 posts views Thread by Xavier Decoret | last post: by
1 post views Thread by Stefan Siegl | last post: by
7 posts views Thread by Alfonso Morra | last post: by
4 posts views Thread by Dilip | last post: by
6 posts views Thread by Andrey Tarasevich | last post: by
104 posts views Thread by JohnQ | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.