1.
http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Name-lookup.html#Name-lookup
2.
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
I quote from (1)
"The C++ standard prescribes ..."
and from (2):
class Xyz { ... }; ← global ("namespace scope") type
void f() { } ← global ("namespace scope") function
template<typename T>
class B {
public:
class Xyz { ... }; ← type nested in class B<T>
void f() { } ← member of class B<T>
};
template<typename T>
class D : public B<T> {
public:
void g()
{
Xyz x; ← suprise: you get the global Xyz!!
f(); ← suprise: you get the global f!!
}
};
-----
It is like the law: everybody has to obey it, even if it illogic, and I feel
it is. if we remove the "template ..." there is no surprise: B:f() has
priority on ::f() :
using namespace std;
#include <iostream>
void f ( ) { cout << "in global :: f()" << endl; }
class B {
public:
void f ( ) { cout << "in B:: f()" << endl; }
};
class D : public B {
public:
void g() {
f ( );
}
};
int main ( ) {
D MyD;
MyD.g();
return 1;
}
This outputs "in B:: f()"
OK?
-------------
I feel that several sections in Stroustrup ( The C++ ... ) are extremely
difficult to read, par 13.6 "Derivation and Templates" is one of them, but the
problem is not mentioned there.
What I am after is how to program 1 template procedure for <T> as well as for
<T*> that reads its input from T, and T* respectively. I can then sort
very large structs as fast as integers using the same procedure, swapping
their addresses instead of the whole strucs.
Stroustrup 13.3.2 seems to describe that, but I cannot see what he is up to.
Who helps me out?
Nieuwenhuizen
2010-09-10T12:58