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 

Why does it apply to non-template but not to template?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
MichaelLi
Guest





PostPosted: Fri May 07, 2004 4:31 pm    Post subject: Why does it apply to non-template but not to template? Reply with quote



//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





PostPosted: Sat May 08, 2004 6:32 am    Post subject: Re: Why does it apply to non-template but not to template? Reply with quote



[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





PostPosted: Mon May 10, 2004 11:21 pm    Post subject: Re: Why does it apply to non-template but not to template? Reply with quote



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





PostPosted: Tue May 11, 2004 3:46 am    Post subject: Re: Why does it apply to non-template but not to template? Reply with quote

[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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards 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.