Re: template function issue
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 12 Dec 2007 18:49:02 -0800
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@xxxxxxxxxxxxxxxxxxxxxxxxx> 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
- Follow-Ups:
- Re: template function issue
- From: Tim Roberts
- Re: template function issue
- References:
- Re: template function issue
- From: Ulrich Eckhardt
- Re: template function issue
- From: George
- Re: template function issue
- From: Doug Harrison [MVP]
- Re: template function issue
- Prev by Date: RE: Robby, __int8 limited to: -128 to 127.
- Next by Date: Robert, try: “ if ( * A1 ++ == 255 ) ++ * A2 ; ”.
- Previous by thread: Re: template function issue
- Next by thread: Re: template function issue
- Index(es):
Relevant Pages
|