Re: template function issue by George
George
Wed Dec 12 18:49:02 PST 2007
Thanks Doug,
Why GetArrayLength(const T(&arr)[size]) works, but
GetArrayLength(const T(arr)[size]) -- I removed & does not work?
regards,
George
"Doug Harrison [MVP]" wrote:
> On Wed, 12 Dec 2007 05:10:01 -0800, George
> <George@discussions.microsoft.com> wrote:
>
> >I do not quite understand why arr is a reference to an array type?
>
> The parameter "arr" has the type, "reference to array of 'size' T". To
> understand why, you have to some basic knowledge of the declaration syntax.
> Do you have a specific question about the syntax?
>
> >In GetArrayLength(const T(&arr)[size]), I have tried to use,
> >
> >typeid(arr).name(),
> >
> >and the result is,
> >
> >char const(*) [12]
> >
> >You mean char const(*) [12] is the same as reference to an array type?
>
> No, that means, "pointer to array of 12 const char", and it's very
> different. For example, the size of that type is sizeof(pointer), while
> sizeof(arr) is the size of the referent, i.e. the array, i.e.
> size*sizeof(T).
>
> >I am confused. :-)
>
> The type_info::name function doesn't have to give useful information, so it
> should not be relied upon to explore the type system. It would be a
> problem, though, if typeid(arr) == typeid(ptr), where ptr has the pointer
> type you introduced above.
>
> --
> Doug Harrison
> Visual C++ MVP
>