From: Barry on
Gary Kedziora wrote:


> // this doesn't work
> template<class T> T fun ( typename outer<T>::inner &c )
> { return c.get(); }
>
> // this works
> //int fun ( outer<int>::inner &c )
> // { return c.get(); }
>
> int main() {
> outer<int>::inner I;
> I.set(3);
> int flop = fun(I);

int flop = fun<int>(I);

> cout << "flop=" << flop << endl;
> return 0;
> }
> ++++#++++0++++#++++0++++#++++0++++#++++0++++#++++0++++#++++0
>


the reason is that you can't do a "reverse deduction" for template
function argument, as the compiler don't know which specialization of
"outter" contains a nested class "inner".
this is like

20.2.2/1
template <class T> struct identity { typedef T type; };

20.2.2/2
[ Note: The use of identity in forward forces users to explicitly
specify the template parameter. This is necessary to get the correct
forwarding semantics. �end note ]

in the C++0x

--
Best Regards
Barry


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]