C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

template class with template as parameter

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Mehturt@gmail.com
Guest





PostPosted: Tue Nov 29, 2005 4:06 pm    Post subject: template class with template as parameter Reply with quote



I have this code which compiles fine under gcc 4:

#include <vector>
#include <string>

template<
typename T = std::string
, template , typename stringize_operation = stringize_fo<T>
Quote:

class Stringizer

{
// member functions here
};

However, when compiling using cxx (Compaq C++ V6.5-014 for Compaq Tru64
UNIX V5.1B (Rev. 2650)) I get the following errors:

cxx: Warning: ***.hh, line 55: declaration of "T" hides template
parameter
, template <typename T> class CONTAINER = std::vector
-------------------------------------^
cxx: Error: ***.hh, line 56: class template "std::vector" is not
compatible with template template parameter "CONTAINER"
, typename stringize_operation = stringize_fo<T>
----------------^

I wonder whether gcc or cxx is correct.
Thanks


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Carl Barron
Guest





PostPosted: Wed Nov 30, 2005 10:56 am    Post subject: Re: template class with template as parameter Reply with quote



In article <1133276845.346304.247910 (AT) o13g2000cwo (DOT) googlegroups.com>,
<"Mehturt (AT) gmail (DOT) com"> wrote:

Quote:
I have this code which compiles fine under gcc 4:

#include <vector
#include
template
typename T = std::string
, template , typename stringize_operation = stringize_fo<T

class Stringizer
{
// member functions here
};

However, when compiling using cxx (Compaq C++ V6.5-014 for Compaq Tru64
UNIX V5.1B (Rev. 2650)) I get the following errors:

cxx: Warning: ***.hh, line 55: declaration of "T" hides template
parameter
, template -------------------------------------^
cxx: Error: ***.hh, line 56: class template "std::vector" is not
compatible with template template parameter "CONTAINER"
, typename stringize_operation = stringize_fo<T
----------------^

I wonder whether gcc or cxx is correct.
Thanks

the template std::vector has two parameters not one and gcc is in

error in extending this. This a major problem with template template
parameters.
either pass the complete container type as a type parameter or require
two parameters of the template template parameter.
[template class vector;]

template
<
class C =std::vector class Op = stringize_to<typename C::value_type>
Quote:
class Stringizer
{

public:
typedef typename C::value_type T;
// ...
};
is probably the 'best' solution, as it will work with any class C
having member functions of std::vector you use in Stringizer, with the
same semantics as those of std::vector and has a member typedef
value_type, the type stored in the container.

More compilers than not will behave as cxx. Technically gcc is
non-standard here.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.