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 default argument redefined

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





PostPosted: Tue Oct 14, 2003 8:52 am    Post subject: Template default argument redefined Reply with quote



template <class Key, class Value, class Compare = std::less
class oo_map;


template< class Key, class Value, class Compare = std::less
class oo_map
{
...
};

I believe it is this construct that is giving an error on the Sun Studio 8
compiler. It complains about a redefinition of a template default argument.
Assuming I didn't type any minor syntax errors above, it this a compiler bug
or a problem with the forward declaration of templates with default
arguments?

(Since the above exists in the bowels of vendor code, it is also possible
that I didn't deduce the real cause of the compiler error)
--
<disclaimer>
Opinions posted are those of the author.
My company doesn't pay me enough to speak for them.
</disclaimer>
--
Jim Melton
Software Architect, Fusion Programs
Lockheed Martin Astronautics
(303) 971-3846




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





PostPosted: Tue Oct 14, 2003 9:07 pm    Post subject: Re: Template default argument redefined Reply with quote



On 14 Oct 2003 04:52:56 -0400, Jim Melton <jim.melton (AT) lmco (DOT) com> wrote:

Quote:
template <class Key, class Value, class Compare = std::less class oo_map;


template< class Key, class Value, class Compare = std::less

should be:

template< class Key, class Value, class Compare>

Quote:
class oo_map
{
...
};

I believe it is this construct that is giving an error on the Sun Studio 8
compiler. It complains about a redefinition of a template default argument.
Assuming I didn't type any minor syntax errors above, it this a compiler bug
or a problem with the forward declaration of templates with default
arguments?

As with function default arguments, you should may only specify a
default template argument in one declaration.

Tom

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

Back to top
Christoph Schulz
Guest





PostPosted: Wed Oct 22, 2003 1:27 am    Post subject: Re: Template default argument redefined Reply with quote



Hello!

Jim Melton <jim.melton (AT) lmco (DOT) com> wrote:

Quote:
template class oo_map;


template< class Key, class Value, class Compare = std::less class oo_map
{
...
};

I believe it is this construct that is giving an error on the Sun
Studio 8 compiler. It complains about a redefinition of a template
default argument. Assuming I didn't type any minor syntax errors
above, it this a compiler bug or a problem with the forward
declaration of templates with default arguments?

The standard says in 14.1/10:

The set of default template arguments available for use with
a template declaration or definition is obtained by merging
the default arguments from the definition (if in scope) and
all declarations in scope in the same way default function
arguments are (8.3.6).

Since 8.3.6/4 forbids redefinition of default arguments ("A default
argument shall not be redefined by a later declaration (not even
to the same value)."), your example is not valid C++, and the
Sun compiler is right to reject it.


Regards,
Christoph



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