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

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

Post by michaelli8 » Sun, 09 May 2004 01:31:05


//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.yqcomputer.com/ ]
 
 
 

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

Post by llewelly.a » Sun, 09 May 2004 15:32:16


XXXX@XXXXX.COM (MichaelLi) writes:

[snip]

http://www.yqcomputer.com/ #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.yqcomputer.com/ ]

 
 
 

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

Post by dsp » Wed, 12 May 2004 08:21:41

Hello llewelly,

llewelly schrieb:

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.yqcomputer.com/ ]
 
 
 

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

Post by llewelly.a » Wed, 12 May 2004 12:46:31


XXXX@XXXXX.COM ("Daniel Krler (nee Spangenberg)") writes:

[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.yqcomputer.com/ ]