Topic: default param for templ functions
Author: "Rani Sharoni" <s3173243@techst02.technion.ac.il>
Date: Mon, 25 Jun 2001 15:12:45 GMT Raw View
The Compiler is right (this time) according to the standard 14.1 - Template
parameters:
-9- ... A default template-argument shall not be specified in a function
template declaration or a function template definition, nor in the
template-parameter-list of the definition of a member of a class template.
Rani.
"Balog Pal (mh)" <pasa@lib.hu> wrote in message
news:3b28f556@andromeda.datanet.hu...
> I just tried to compile my code that compiled well on msvc5, on msvc6sp5.
>
> I get a warning for the following construct:
>
> template<class TYPE, class LIST = TYPE::tList>
> int ReadTableL( LIST & list, LPCSTR filter, LPCSTR order,
> CGenRecsetBase * pRset = 0 ) {...}
>
> Now I get
>
> warning C4519: default template arguments are only allowed on a class
> template; ignored
>
> btw this warning in not in the help database either, looks like some
hidden
> new feature. :-o
>
> So my question is, whether it is a new C++ language feature, or just a MS
> decision, and if the former, why isn't it allowed to have default args for
> functions, when it worked well in old compilers, even those with poor
> template support.
>
> Paul
>
>
>
>
>
>
>
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Wed, 20 Jun 2001 07:32:31 GMT Raw View
In article <3b2f2dd9@andromeda.datanet.hu>, mh says...
>, could you help me out with my offending template:
>
>>> template<class TYPE, class LIST = TYPE::tList>
>>> int ReadTableL( LIST & list, LPCSTR filter, LPCSTR order,
>>> CGenRecsetBase * pRset = 0 ) {...}
>
>Here TYPE has a default list, ant that is used some 90% of the time. In
>the rest some other list class is passed, that can differ from the default,
>but support the same interface.
>
>Paul
The "obvious" solution is to add the overload
template <typename TYPE>
int ReadTabeL ( TYPE::tList & list, const string& filter,
const string& order, CGenRecsetBase* pRset=0 ) {...}
LPCSTR can be converted to std::string.
Regards,
Michiel Salters
--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Steve Clamage <clamage@eng.sun.com>
Date: Tue, 19 Jun 2001 00:03:30 GMT Raw View
On Thu, 14 Jun 2001, Balog Pal (mh) wrote:
>
> I just tried to compile my code that compiled well on msvc5, on msvc6sp5.
>
> I get a warning for the following construct:
>
> template<class TYPE, class LIST = TYPE::tList>
> int ReadTableL( LIST & list, LPCSTR filter, LPCSTR order,
> CGenRecsetBase * pRset = 0 ) {...}
>
> Now I get
>
> warning C4519: default template arguments are only allowed on a class
> template; ignored
>
> btw this warning in not in the help database either, looks like some hidden
> new feature. :-o
>
> So my question is, whether it is a new C++ language feature, or just a MS
> decision, and if the former, why isn't it allowed to have default args for
> functions, when it worked well in old compilers, even those with poor
> template support.
Default template parameters are a relatively new feature, but they
have never been allowed on function templates. Compilers that allow
them are incorrect, or allow them as a non-standard extension.
The reason default template parameters are not allowed on function
templates is because they interact badly with overloading and
default argument values. You also don't need the feature, because
you can overload function templates.
---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Bartlomiej Nicka" <bartekn@sgi.net.pl>
Date: Tue, 19 Jun 2001 16:44:43 GMT Raw View
In article <3b28f556@andromeda.datanet.hu>, "Unknown" <pasa@lib.hu> wrote:
> I just tried to compile my code that compiled well on msvc5, on
> msvc6sp5. I get a warning for the following construct: template<class
> TYPE, class LIST = TYPE::tList> int ReadTableL( LIST & list, LPCSTR
> filter, LPCSTR order, CGenRecsetBase * pRset = 0 ) {...} Now I get
> warning C4519: default template arguments are only allowed on a class
> template; ignored
> btw this warning in not in the help database either, looks like some
> hidden new feature. :-o
> So my question is, whether it is a new C++ language feature, or just a
> MS decision, and if the former, why isn't it allowed to have default
> args for functions, when it worked well in old compilers, even those
> with poor template support.
> Paul
The C++ standard says that a default template-argument cannot be speciified
in a function template declaration or definition. It's because a default
template-arguments cannot be used to influence template argument deduction.
I suppose that behavior of M$VC in this point is non-standard when allowing
to create such statements (but I can be wrong - I don't know M$VC at all).
Bartek
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Balog Pal (mh)" <pasa@lib.hu>
Date: Tue, 19 Jun 2001 16:44:21 GMT Raw View
Steve Clamage wrote in message ...
>Default template parameters are a relatively new feature, but they
>have never been allowed on function templates. Compilers that allow
>them are incorrect, or allow them as a non-standard extension.
>
>The reason default template parameters are not allowed on function
>templates is because they interact badly with overloading and
>default argument values.
Too bad. :-(
>You also don't need the feature, because
>you can overload function templates.
Well, that 'I don't need part noy yet occoured to me, could you help me out
with my offending template:
>> template<class TYPE, class LIST = TYPE::tList>
>> int ReadTableL( LIST & list, LPCSTR filter, LPCSTR order,
>> CGenRecsetBase * pRset = 0 ) {...}
Here TYPE has a default list, ant that is used some 90% of the time. In
the rest some other list class is passed, that can differ from the default,
but support the same interface.
Paul
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Tue, 19 Jun 2001 17:06:22 GMT Raw View
In article <Pine.SOL.3.96.1010618134935.24374C-100000@taumet>, Steve
Clamage <clamage@eng.sun.com> writes
>The reason default template parameters are not allowed on function
>templates is because they interact badly with overloading and
>default argument values. You also don't need the feature, because
>you can overload function templates.
And you do not need them for template classes because you can provide a
partial specialisation. The only place where default arguments have any
serious positive impact on code is with ctors. And if we could, as I
have proposed elsewhere, have a syntax for delegating construction they
would not be needed there either.
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Balog Pal (mh)" <pasa@lib.hu>
Date: Thu, 14 Jun 2001 22:50:04 GMT Raw View
I just tried to compile my code that compiled well on msvc5, on msvc6sp5.
I get a warning for the following construct:
template<class TYPE, class LIST = TYPE::tList>
int ReadTableL( LIST & list, LPCSTR filter, LPCSTR order,
CGenRecsetBase * pRset = 0 ) {...}
Now I get
warning C4519: default template arguments are only allowed on a class
template; ignored
btw this warning in not in the help database either, looks like some hidden
new feature. :-o
So my question is, whether it is a new C++ language feature, or just a MS
decision, and if the former, why isn't it allowed to have default args for
functions, when it worked well in old compilers, even those with poor
template support.
Paul
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]