Topic: Why does it apply to non-template but not to template?
Author: michaelli8195@hotmail.com (MichaelLi)
Date: Fri, 7 May 2004 16:31:05 +0000 (UTC) Raw View
//Simple testcase:
//
#include <iostream>
#include <string>
template<typename T>
void f(T, const std::string);
template<typename T>
void f(T, const std::string s = " ") {}
void g(T, const std::string);
void g(T, const std::string s = " ") {}
int main()
{
f(1); // error, why?
g(1); // OK
}
I use gcc 3.33 and it reads "error: no matching function for call to
`fun(int)'
". In the C++ Standard 8.3.6.4, it specifies "For non-template
functions, default arguments can be added in later declarations". It
seems that the code above is invalid. But why? Why does it just
applies to non-template version but not to the template one?
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Sat, 8 May 2004 06:32:16 +0000 (UTC) Raw View
michaelli8195@hotmail.com (MichaelLi) writes:
> //Simple testcase:
> //
> #include <iostream>
> #include <string>
> template<typename T>
> void f(T, const std::string);
>
> template<typename T>
> void f(T, const std::string s = " ") {}
>
> void g(T, const std::string);
> void g(T, const std::string s = " ") {}
>
> int main()
> {
> f(1); // error, why?
> g(1); // OK
> }
>
> I use gcc 3.33 and it reads "error: no matching function for call to
> `fun(int)'
> ". In the C++ Standard 8.3.6.4, it specifies "For non-template
> functions, default arguments can be added in later declarations". It
> seems that the code above is invalid. But why? Why does it just
> applies to non-template version but not to the template one?
[snip]
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#226
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: dsp@bdal.de (=?ISO-8859-1?Q?=22Daniel_Kr=FCgler_=28nee_Spangenberg=29=22?=)
Date: Mon, 10 May 2004 23:21:41 +0000 (UTC) Raw View
Hello llewelly,
llewelly schrieb:
>michaelli8195@hotmail.com (MichaelLi) writes:
>
>
>
>>//Simple testcase:
>>//
>>#include <iostream>
>>#include <string>
>>template<typename T>
>>void f(T, const std::string);
>>
>>template<typename T>
>>void f(T, const std::string s = " ") {}
>>
>>void g(T, const std::string);
>>void g(T, const std::string s = " ") {}
>>
>>int main()
>>{
>> f(1); // error, why?
>> g(1); // OK
>>}
>>
>>I use gcc 3.33 and it reads "error: no matching function for call to
>>`fun(int)'
>>". In the C++ Standard 8.3.6.4, it specifies "For non-template
>>functions, default arguments can be added in later declarations". It
>>seems that the code above is invalid. But why? Why does it just
>>applies to non-template version but not to the template one?
>>
>>
>[snip]
>
>http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#226
>
>
The quoted defect report is not related to the specified problem. The
poster is talking about
(non-template parameter) default arguments, while report #226 is about
default **template** arguments,
which are currently forbidden.
Greetings from Bremen,
Daniel
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Tue, 11 May 2004 03:46:31 +0000 (UTC) Raw View
dsp@bdal.de ("Daniel Kr=FCgler (nee Spangenberg)") writes:
> Hello llewelly,
>
> llewelly schrieb:
>
>>michaelli8195@hotmail.com (MichaelLi) writes:
>>
>> =20
>>>//Simple testcase:
>>>//
>>>#include <iostream>
>>>#include <string>
>>>template<typename T>
>>>void f(T, const std::string);
>>>
>>>template<typename T>
>>>void f(T, const std::string s =3D " ") {}
>>>
>>>void g(T, const std::string);
>>>void g(T, const std::string s =3D " ") {}
>>>
>>>int main()
>>>{
>>> f(1); // error, why?
>>> g(1); // OK }
>>>
>>>I use gcc 3.33 and it reads "error: no matching function for call to
>>>`fun(int)'
>>>". In the C++ Standard 8.3.6.4, it specifies "For non-template
>>>functions, default arguments can be added in later declarations". It
>>>seems that the code above is invalid. But why? Why does it just
>>>applies to non-template version but not to the template one?
>>> =20
>>[snip]
>>
>>http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#226
>> =20
> The quoted defect report is not related to the specified problem. The
> poster is talking about
> (non-template parameter) default arguments, while report #226 is about
> default **template** arguments,
> which are currently forbidden.
[snip]
Yes, somehow I misread it. Sorry.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]