This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: template class scoping rules
- From: David Fang <fang at csl dot cornell dot edu>
- To: Matthew J Fletcher <mfletcher at serck-controls dot co dot uk>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Tue, 14 Mar 2006 04:55:37 -0500 (EST)
- Subject: Re: template class scoping rules
Hi,
Since 3.4, (template-)dependent lookup has been changed to conform
to the standard. In particular, from http://gcc.gnu.org/gcc-3.4/changes.html:
"In a template definition, unqualified names will no longer find members
of a dependent base."
This allows lookups to be bound at template instantiation time.
(Consider the case where Two<foo> is specialized after Three<T> is
defined, but before Three<foo> is instantiated.)
Two<T> is a dependent base of Three<T>. Another way of qualifying the
name to lookup is to use "this->m_Public".
HTH
Fang
> test.cpp: In constructor 'Three<T>::Three()':
> test.cpp:20: error: 'm_Public' was not declared in this scope
>
> class One
> {
> public:
> One();
> ~One();
>
> public:
> int m_Public;
> };
>
> template <class T> class Two : public One
> {
> public:
> Two() {m_Public = 0;}
> };
>
> template <class T> class Three : public Two<T>
> {
> public:
> Three() {m_Public = 0;}
> };