templates, namespace, and name lookup

S

Stefan Naewe

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-----
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top