C
Chris Jefferson
I came across an unusual problem recently.. I think that I've can see
why it's done, but it's still annoying. I was just wondering if I should
have this problem (it came up in g++ for me)
Consider the following (very reduced!) piece of code.
struct foo {};
template<typename U>
void bar(U u = foo())
{ }
Now, lets try to use bar:
bar(1); //works
bar<foo>(); //works
bar(); //"No matching function to bar()"
It seems slightly strange that this doesn't work.. at the moment I'm
having to fix this the "old fashioned way", by adding (after removing
the default parameter definition for bar)
void bar()
{ bar(foo()); }
Which works fine.. I'm still not clear on why it shouldn't be able to
perform the deduction however?
Chris
why it's done, but it's still annoying. I was just wondering if I should
have this problem (it came up in g++ for me)
Consider the following (very reduced!) piece of code.
struct foo {};
template<typename U>
void bar(U u = foo())
{ }
Now, lets try to use bar:
bar(1); //works
bar<foo>(); //works
bar(); //"No matching function to bar()"
It seems slightly strange that this doesn't work.. at the moment I'm
having to fix this the "old fashioned way", by adding (after removing
the default parameter definition for bar)
void bar()
{ bar(foo()); }
Which works fine.. I'm still not clear on why it shouldn't be able to
perform the deduction however?
Chris