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

|
Related Articles |
|
|