On 12 Mai, 00:41, rolkA <samy.ro...@[EMAIL PROTECTED]
> wrote:
> Ok so consider this code :
>
> namespace Bar
> {
> template <class T2>
> T2 f()
> {
> return T2(0);
> }
> }
>
> template <class T>
> void Foo(float y = Bar::f<float>())
> {
> }
>
> int main()
> {
> Foo<int>(); // C2783: 'T2 Bar::f(void)' : could not deduce
template
> argument for 'T2'
> return 0;
> }
>
> It does not compile with Visual C++ 2005 and 2008, but G++ has no
> problem with it.
This is clearly a compiler error in VS2005/VS2008.
In your example, there is nothing left to be deduced
for function template Bar::f, because all template
parameters are provided. I only can assume that the
compiler "thinks" here, that you attempt to deduce
Foo's template parameter via default arguments (which
is not allowed), but this is just a guess.
> But now, if I remove the template from Foo, it works :
>
> namespace Bar
> {
> template <class T2>
> T2 f()
> {
> return T2(0);
> }
>
> };
>
> void Foo(float y = Bar::f<float>())
> {
> }
>
> int main()
> {
> Foo<int>(); // no problem
This should be diagnosed, I assume you meant
Foo();
here.
> return 0;
> }
>
> And if f is not in a namespace, it works too :
>
> template <class T2>
> T2 f()
> {
> return T2(0);
> }
>
> template <class T>
> void Foo(float y = f<float>())
> {
> }
>
> int main()
> {
> Foo<int>(); // no problem
> return 0;
> }
>
> Any idea ? Thank you.
I suggest that you send a bug re****t to MS, presenting
the first example code.
Greetings from Bremen,
Daniel Krügler
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|