tags:

views:

47

answers:

3

hello!

I'm struggling with compile error C3200

http://msdn.microsoft.com/en-us/library/3xwxftta.aspx discusses the problem and gives as an example:

// C3200.cpp
template<typename T>
class X
{
};

template<template<typename U> class T1, typename T2>
class Y
{
};

int main()
{
   Y<int, int> y;   // C3200
}

and suggests that instead

Y<X, int> y; 

must be used. but i don't really understand this... why can't it be

Y<X<int>, int> y;

? that would make more sense for me because in the suggested way the actual type of y is still not really defined.. if i extend the given example with some variables i get this:

// C3200.cpp
template<typename T>
class X
{
    char someChar;
    T someOtherVar;
};

template<template<typename U> class T1, typename T2>
class Y
{
    T1 var1;
    T2 var2;
};

so if i just specify Y y; as in the suggested solution, the compiler still does not know how many bytes to reserve for y - no?

can someone explain me what's going on?

thanks!

+1  A: 
template<template<typename U> class T1, typename T2>

Here T1 is a so-called "template template parameter". It means it should accept a template. X is a template, X<int> is instantiated to a class.

template<template<typename U> class T1, typename T2>
class Y
{
    T1 var1;
    T2 var2;
};

This does not compiles because T1 is a template, not a type. To make T1 a type, you need to pass a parameter to it e.g.

template<template<typename U> class T1, typename T2>
class Y
{
    T1<T2> var1;
    T2 var2;
};
KennyTM
good explanation! i understood template template parameters wrong. now it's clear, thank you!
Mat
A: 

My understanding of the issue is that the first template type of Y should be a templated type in and of itself. X would be a templated type whereas X<int> is an instantiation of that type and doesn't meet the criteria for Y's first template parameter.

fbrereto
+2  A: 

C3200 complains that the first "int" in "Y<int, int>" can not be forced to match "template<typename U> class T1" because that int is not a template type. That is the only issue that C3200 is raising. However, "X<int>" would also be wrong because that would be a nontemplate type. The first parameter has to be a templated type, not a "fully resolved" type.

Eric Towers