473,324 Members | 2,179 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,324 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 1514
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: 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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.