question about out of line class definition

I

Ivan Sorokin

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.

Is this code correct? What is the general rule about how a name
qualifier in out of line class definition should be treated?
 
V

Victor Bazarov

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
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
 
W

Werner

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.



Is this code correct? What is the general rule about how a name

qualifier in out of line class definition should be treated?

It is possible for z to be a non template when x has a
specialization e.g (an abc in this case here below):

struct g
{
template <class T> class z;
};

template <class T>
struct x
{
typedef g y; //z a template...
};

struct abc
{
typedef int type;
};

struct h
{
typedef abc z;
};

template <>
struct x<int>
{
typedef h y; //y an h for x<int>, which
// makes z an abc...
};

template <typename T>
struct x<T>::y::z
{
int b;
};

int main()
{
return x<int>::y::z::type( 0 );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top