Discussion:
Template compilation
(too old to reply)
Vladimir Grigoriev
2010-01-18 14:16:02 UTC
Permalink
Why is not compiled the following code in Visual C++ 2005 EE?

template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}

Vladimir Grigoriev
Victor Bazarov
2010-01-18 14:25:34 UTC
Permalink
Post by Vladimir Grigoriev
Why is not compiled the following code in Visual C++ 2005 EE?
template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
What does your question mean? Could you perhaps rephrase it? What do
you expect, and why? What do you get? Post *complete* code and the
compiler output and explain how it is different from what you expect.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Vladimir Grigoriev
2010-01-18 14:46:43 UTC
Permalink
Victor I get the following errors

------ Build started: Project: lab_test, Configuration: Debug Win32 ------

Compiling...

lab_test.cpp

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(51) : error C2988: unrecognizable
template declaration/definition

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(51) : error C2059: syntax error :
'<L_TEMPLATEDECL>'

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C2143: syntax error :
missing ';' before '<'

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C2433: 'Container' :
'inline' not permitted on data declarations

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C4430: missing type
specifier - int assumed. Note: C++ does not support default-int

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C2988: unrecognizable
template declaration/definition

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C2059: syntax error : '<'

c:\documents and settings\vgrigoryev\my documents\visual studio
2005\projects\lab_test\lab_test.cpp(48) : error C2039: 'size_type' : is not
a member of '`global namespace''

Build log was saved at "file://c:\Documents and Settings\vgrigoryev\My
Documents\Visual Studio 2005\Projects\lab_test\Debug\BuildLog.htm"

lab_test - 8 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Vladimir Grigoriev
Post by Vladimir Grigoriev
Why is not compiled the following code in Visual C++ 2005 EE?
template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
What does your question mean? Could you perhaps rephrase it? What do you
expect, and why? What do you get? Post *complete* code and the compiler
output and explain how it is different from what you expect.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Igor Tandetnik
2010-01-18 16:39:43 UTC
Permalink
Post by Vladimir Grigoriev
Why is not compiled the following code in Visual C++ 2005 EE?
template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
You must use the keyword 'class', not 'typename', with template template parameters.

template <template <typename T, typename A> class Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Vladimir Grigoriev
2010-01-18 16:51:55 UTC
Permalink
Thanks, Igor.
However the Standard if I am not mistaken says that there is no any
difference of using typename and class when template parameters are defined,
is there?

Vladimir Grigoriev
Post by Vladimir Grigoriev
Why is not compiled the following code in Visual C++ 2005 EE?
template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
You must use the keyword 'class', not 'typename', with template template
parameters.

template <template <typename T, typename A> class Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A> &c )
{
return ( c.size() );
}
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily
a good idea. It is hard to be sure where they are going to land, and it
could be dangerous sitting under them as they fly overhead. -- RFC 1925
Bo Persson
2010-01-18 17:04:29 UTC
Permalink
Post by Vladimir Grigoriev
Thanks, Igor.
However the Standard if I am not mistaken says that there is no any
difference of using typename and class when template parameters are
defined, is there?
Correct, but with template template parameters there *is* a
difference.


Bo Persson
Post by Vladimir Grigoriev
Vladimir Grigoriev
Post by Vladimir Grigoriev
Why is not compiled the following code in Visual C++ 2005 EE?
template <template <typename T, typename A> typename Container,
typename T, typename A>
inline typename Container<T, A>::size_type size( Container<T, A>
&c ) {
return ( c.size() );
}
You must use the keyword 'class', not 'typename', with template template parameters.
Igor Tandetnik
2010-01-18 17:03:38 UTC
Permalink
Post by Vladimir Grigoriev
However the Standard if I am not mistaken says that there is no any
difference of using typename and class when template parameters are defined,
is there?
... where the syntax allows both. See the grammar in 14.1p1.

Really, given your apparent interest in fine details of the language, I suggest you get a copy of the standard (I have given you the links to free downloads earlier) and learn to read it.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Continue reading on narkive:
Loading...