From -1943631641077103193
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,f3e8f06baea88d92
X-Google-Attributes: gidf78e5,public
From: "Ross Smith" <ross.s@ihug.co.nz>
Subject: Re: typename rationale question
Date: 1998/12/16
Message-ID: <759ab2$lm2$1@newsource.ihug.co.nz>#1/1
X-Deja-AN: 423039112
X-NNTP-Posting-Host: animal.ihug.co.nz
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <758pdf$gq7$1@news1-alterdial.uu.net>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset="iso-8859-1"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: The Internet Group
Mime-Version: 1.0
Newsgroups: comp.std.c++
Originator: clamage@taumet


Brad Daniels wrote in message <758pdf$gq7$1@news1-alterdial.uu.net>...
>
>I like the introduction of the typename keyword for template parameters,
>since the parameter type may not be classes, but I'm a bit confused as to
>why typename can only be used in that limited context.  It seems completely
>natural and highly desirable to use it for forward declarations as well.
>For example:
>
>typename A;
>
>class B {
>   A *aPtr;
>//...
>};
>
>At this point, A could be an enumerator, a class, a built-in type, or a
>typedef.  Class B doesn't care or need to know what A actually is, other
>than that it is a type.

Not true, I'm afraid. All class pointers are required to have the same
implementation (sometimes expressed as "all classes smell the same"),
which is why you can get away with just saying "class A" in this sort
of context; knowing that A is a class gives the compiler enough
information to handle pointers to A correctly (provided they're not
dereferenced, obviously).

But that's not true of pointers to other types. Pointers to different
arbitrary types, which may or may not be classes, are *not* required
to have the same implementation. Merely knowing that A is the name of
a type is not enough information for the compiler to know how to handle
an A*.

On most modern 32-bit microprocessor systems, all pointers usually do
have the same representation. But that's just an artifact of a specific
kind of byte-addressable architecture, not a universal law. On a
word-addressable machine, for example, pointers to objects smaller than
a word (e.g. char*) will often have extra bits in them.

--
Ross Smith ................................... mailto:ross.s@ihug.co.nz
.............. The Internet Group, Auckland, New Zealand ..............
                               * * * * *
    To err is human. To really screw up requires the root password.




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




