Dizzy wrote:
> Zorro wrote:
>
> > Let us look at this from a different angle, before dismissing it. Note
> > that, at "Test()" an object is in fact created, within the same scope
> > as the reference to it. So, within that scope, t can indeed reach the
> > object. This is not in voilation of object-oriented view, though it may
> > violate the standard.
>
> So you wonder what is the reasoning behind that decision in the standard ?
>
> > However, C++ takes the C built-in types as is. Then, the literal 10 is
> > not an object (not an l-value for C). There is nothing to point to
> > because a literal for a built-in is only available during compilation
> > unless it is assigned to an object (of its type).
>
> But for references to const C++ allows to bind to a literal like that.
>
> int const& i = 10;
> (the compiler will create a temporary in the same scope)
>
> It's someway unified that references to const are allowed to temporaries
> even to literals like that and it makes programming typeless interfaces (ie
> templates) easier.
>
> --
> Dizzy
> http://dizzy.roedu.net
The compiler error already indicated that it could do it for const. How
is const related to what I said?
I am aware of C++ templates accepting literals like "10", instead of
types. That is because C++ template instantiation is done the same way
C macros are, i.e. text editing. I am not objecting to this, just
saying how it works, and that is the way one should accept it.
Please note that I was explaining why VC++ did not generate error for
Test(). That is because, Test() is an object (after elaboration). There
is no const involved in my response.
Thanks for your comment, though.
Regards.