Template function with two classes rejects default arguments

Hello,
It seems a template with two generic types prevents default values from being recognized.
1
2
3
4
5
6
7
8
template <class T, class S> void fubar(T foo, S bar = 0) {}
template <class T>          void rabuf(T foo, T bar = 0) {}

int main (int argc, char * const argv[]) {
    rabuf(0);	// No problem
    fubar(0);	// ERROR! No matching function for call to 'fubar(int)'
    fubar(0,0);	// No problem
}

Does anyone know how to fix this (other than using 2^n overloads)?
Thanks in advance.
How about
1
2
3
4
template <typename T>
void foobar2(T foo){
    foobar<T,int>(foo);
}
?
My current solution is similar to that.
1
2
template <class T> void fubar(T foo) { fubar(foo, 0); }
template <class T, class S> void fubar(T foo, S bar = 0) {}

The thing is, it scales messily for more parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void fubar() {
    fubar(0, 0, 0, 0, 0);
}
template <class T> void fubar(T a) {
    fubar(a, 0, 0, 0, 0);
}
template <class T, class S> void fubar(T a, S b) {
    fubar(a, b, 0, 0, 0);
}
template <class T, class S, class R> void fubar(T a, S b, R c) {
    fubar(a, b, c, 0, 0);
}
template <class T, class S, class R, class Q> void fubar(T a, S b, R c, Q d) {
    fubar(a, b, c, d, 0);
}
template <class T, class S, class R, class Q, class P> void fubar(T a, S b, R c, Q d, P e) {
    ... // Do something
}


This seems much worse than
1
2
3
template <class T, class S, class R, class Q, class P> void fubar(T a = 0, S b = 0, R c = 0, Q d = 0, P e = 0) {
    ... // Do something
}


Basically, I like having default parameters. I don't want to resort to a Java-like kluge like the one above.
Topic archived. No new replies allowed.