By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,291 Members | 3,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,291 IT Pros & Developers. It's quick & easy.

Template template parameter and typename

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.