469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Default template arguments in function templates

Hi all,

I have the following two template function definitions:

template <typename Container, typename Sepatator>
string join(const Container& c, const Sepatator& s) {
// ...
}

template <typename Container>
string join(const Container& c) {
return join(c, ' ');
}

I tried to merge them into one using a default argument for Separator, but the compiler (gcc 3.3.1)
complains that default template arguments may not be used in function templates. What's the reason
for this limitation and, more importantly, is there a workaround for it ?

TIA,
George

Oct 4 '05 #1
1 4755
George Sakkis wrote:
I have the following two template function definitions:

template <typename Container, typename Sepatator>
string join(const Container& c, const Sepatator& s) {
// ...
}

template <typename Container>
string join(const Container& c) {
return join(c, ' ');
}

I tried to merge them into one using a default argument for Separator, but the compiler (gcc 3.3.1)
complains that default template arguments may not be used in function templates. What's the reason
for this limitation and, more importantly, is there a workaround for it ?


Ask in comp.std.c++ bout the reasoning behind prohibiting the default
template arguments for function templates, they discuss the actual
Standard document, they know the rationales for different parts of it
for sure. As to the work-around, you already have it: don't merge, keep
the two functions separate.

V
Oct 4 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Patrick Kowalzick | last post: by
2 posts views Thread by Michael Stembera | last post: by
1 post views Thread by Arne Petersen | last post: by
reply views Thread by Chris Thomasson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.