Template template parameter and typename



 DEVELOP > c-Plus-Plus > Template template parameter and typename

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "I wish"
Date: 24 Jun 2004 09:31:53 PM
Object: Template template parameter and typename
I wrote some test code
template <typename T>
class A {};
class B{};
template < template <typename T> typename U >
class C {};
int main( void )
{
typedef C< A > my;
return 0;
}
But I get compile error
t.cc:6: error: parse error before `typename'
t.cc:9: error: cannot declare `::main' to be a template
t.cc:9: error: too many template parameter lists in declaration of `int main()'
t.cc:9: error: syntax error before `{' token
So I chenge the second typename in line 6 to class, then the code
can compile correctly.
Why I can't use typename in original code? I think typename in template
parameter can replace class.
--
|
___
(-_-)
<| |>---------------------------------- ShepJeng.twbbs.org -------------
/ cherry.cs.nccu.edu.tw
.

User: "Denis Remezov"

Title: Re: Template template parameter and typename 24 Jun 2004 06:25:39 PM
I wish wrote:


I wrote some test code

template <typename T>
class A {};

class B{};

template < template <typename T> typename U >
class C {};
int main( void )
{
typedef C< A > my;
return 0;
}

But I get compile error
t.cc:6: error: parse error before `typename'
t.cc:9: error: cannot declare `::main' to be a template
t.cc:9: error: too many template parameter lists in declaration of `int main()'
t.cc:9: error: syntax error before `{' token

So I chenge the second typename in line 6 to class, then the code

can compile correctly.

Why I can't use typename in original code? I think typename in template

parameter can replace class.

"typename" and "class" are interchangeable when declaring a type-name (T).
U is not a type-name but a template-name, and must be declared with "class".
Think of it as in a declaration
template <typename T> class U; //cannot say "... typename U"
Denis
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER