 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
MichaelLi Guest
|
Posted: Fri May 07, 2004 4:31 pm Post subject: Why does it apply to non-template but not to template? |
|
|
//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 ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Sat May 08, 2004 6:32 am Post subject: Re: Why does it apply to non-template but not to template? |
|
|
[email]michaelli8195 (AT) hotmail (DOT) com[/email] (MichaelLi) writes:
| Quote: | //Simple testcase:
//
#include
#include
template
void f(T, const std::string);
template
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 ]
|
|
| Back to top |
|
 |
Daniel Krügler Guest
|
Posted: Mon May 10, 2004 11:21 pm Post subject: Re: Why does it apply to non-template but not to template? |
|
|
Hello llewelly,
llewelly schrieb:
| Quote: | michaelli8195 (AT) hotmail (DOT) com (MichaelLi) writes:
//Simple testcase:
//
#include
#include
template
void f(T, const std::string);
template
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 ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Tue May 11, 2004 3:46 am Post subject: Re: Why does it apply to non-template but not to template? |
|
|
[email]dsp (AT) bdal (DOT) de[/email] ("Daniel Krügler (nee Spangenberg)") writes:
| Quote: | Hello llewelly,
llewelly schrieb:
[email]michaelli8195 (AT) hotmail (DOT) com[/email] (MichaelLi) writes:
//Simple testcase:
//
#include
#include
template
void f(T, const std::string);
template
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.
[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 ]
|
|
| Back to top |
|
 |
|
|
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
|
|