Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Is this sta...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 9590 of 9823
Post > Topic >>

Re: Is this standard, or Visual C++ bug ?

by =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@[EMAIL PROTECTED] May 12, 2008 at 09:43 AM

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! ]
 




 4 Posts in Topic:
Is this standard, or Visual C++ bug ?
rolkA <samy.rolka@[EMA  2008-05-11 16:41:13 
Re: Is this standard, or Visual C++ bug ?
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-12 09:43:30 
Re: Is this standard, or Visual C++ bug ?
rolkA <samy.rolka@[EMA  2008-05-14 17:52:45 
Re: Is this standard, or Visual C++ bug ?
Andrey Tarasevich <and  2008-05-14 17:52:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:35:34 CDT 2008.