473,226 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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
2 1508
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fritz Bosch | last post by:
Hi experts Is is possible to import/manipulate a module such that I can supply its __dict__? I want to supply my own dict subclass object to be filled by the import, e.g. a class like: >>>...
2
by: Xavier Decoret | last post by:
The following code does not compoile with gcc-3.2.3 namespace dummy { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Interface of Foo...
1
by: Stefan Siegl | last post by:
Hello, I am trying to learn XSLT to use it in another project. I start reading the book "Java and XSLT" and tried the examples and they are went quite fine (how suprising *g*). Then I tried...
8
by: Bernd Fuhrmann | last post by:
Hi! I just tried to write a little program, but GCC (Mingw 3.3.1) refused to compile it. So I'd like to know if there's something wrong with my code or if it is a bug in GCC. ---snip---...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
7
by: Alfonso Morra | last post by:
I have written a class, and several of it's methods are function templates. When I compiled the code, I realized that I had made some typos in the code - but the compiler seemed to skip right over...
4
by: Dilip | last post by:
How did the Koenig lookup come to be associated with templates? If I have something like this: (no template code) namespace X { enum E { e1 }; void f(E) { } }
6
by: Andrey Tarasevich | last post by:
Hello Consider the following code fragment namespace N { struct S { void foo(); }; }
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.