Re: qualified name and unqualified name
On Mar 7, 10:30 am, George <Geo...@discussions.microsoft.com> wrote:
I think qualified name means names with namespace qualifier in this contex=
t?
Unqualified name means no namespace qualifier ahead of a name? Correct or =
not?
Not just namespaces. Could be classes as well, for example, base
classes. Qualifications can be better interpreted in terms of scope
resolution operator (::). Anything (a member, member function of base
classes, global or in a certain namespace(nested or not)) can be
explicitly qualified using ::. That is called qualification or a
qualified name. Others are unqualified (of their scope).
--------------------
Not can an unqualified name used in a template ever be bound to a local
name. Finally, even if a template is first used within a class, unqualifie=
d
names used in the template will not be bound to members of that class.
Ignoring lcoal names is essential to prevent a lot of nasty macro-like
behavior.
section C.18.3.3 Point of Instantiation Binding
--------------------
If you are referring to certain section, atleast take care in
mentioning the section correct. I looked for 18.3.3 (actually its
13.8.3), it doesn't exist in TC++PL 3ed. There isn't even a section C.
However, there is an Appendix C.
I looked into the section and what it is suggesting needs an
understanding of "point of instantiation". As it says clearly, point
of instantiation is the point in the nearest global or namespace scope
enclosing the use of a template (just before the declaration that
contains the use).
What the above is probably suggesting is that, if you use an
unqualified name (without using scope resolution to explicitly inform
the compiler where to look for the name you use), it will never
resolve to anything declare in local scope of that template's use. The
lookup is done in the scope of the point of instantiation.
For example,
//struct defined in nearest global or namespace scope "enclosing
template use" or having the point of instantiation (which is just
outside/before main())
struct B{B(){std::cout << "outer B";}};
template<class T>
struct A
{
T t;
};
//--->> (2) This is the point of instantiation.
int main()
{
struct B{B(){std::cout << "local B";}};
A<B> a; //--->> (1) this is where the template is used so the
point of instantiation for this template is
// the nearest global (it is as we have
no namespaces here) or namespace scope "enclosing the use"
// Now, look just above main -> that
scope encloses main and hence the scope enclosing the use.
}
The above code should cause to print "outer B". That is what I think
that section suggests.
But, I ran it with VS 2005 and it seems to be instantiating from the
local struct B. It prints "local B" (when according to what I
understand it should print "outer B"). However, comeau rejects to
compile the code even (when it should compile fine, ignore local B for
instantiation and use outer B definition, commenting out outer B
should have led to a compile error). According to TC++PL, it should
simply ignore the local B in main() and instantiate using the global
definition of B. The examples in TC++PL, are not very illustrative
around this (esp. the 2nd one with vector declaration inside function
f()).
Seems I am missing something.