Initialization of a static member of a template class fails

John Love-Jensen eljay@adobe.com
Fri Dec 21 17:43:00 GMT 2007


Hi Jean-Michel,

> I don't undertand why with the latest release (3.4.6) of gcc we use (it was
> OK with 3.2.3 release), Main.cpp doesn't compile if I don't define USE_THIS:

ISO 14882 requires two-phase lookup.  That means that the m_CTemp1 is not
visible in the context of CTemp2 without explicitly qualifying that it is in
reference to this->m_CTemp1 or to CTemp1<T>::m_CTemp1 or providing a using
CTemp1<T>::m_CTemp1 statement.

Previous versions of GCC did not use two-phase lookup, and were not
compliant with ISO 14882 on that issue.  (Which incurred other potentially
insidious misbehavior.)

> In fact, I don't undertand why the line t2.m_CTemp1 = 3; is correct in
> Main.cpp and not m_CTemp1 = 3; in CTemp2_affecter().

In main, the t2.m_CTemp1 has CTemp2 instantiated, and hence is not affected
by the two phase lookup.  The "t2." part is sufficient to access the public
member variable.

Happy holidays,
--Eljay



More information about the Gcc-help mailing list