On 11-11-27 08:05 AM, Francis Glassborow wrote:
I find it confusing to describe a pointer as having a dynamic type.
I've always understood that the pointee or referent can have a dynamic
type different (derived) from its static type, but that pointers have
only one type. If you describe the pointer as having a dynamic type,
then its (dynamic) type can change over its lifetime, whereas otherwise
the type of an object is constant. Am I misinformed?
I do not think that it is a matter of being (mis)informed but rather a
matter of how we use English to describe a situation which we both
understand, Whatever is being pointed at or referred to will not change
its type during its lifetime, none the less the pointer (and when it is
an parameter or return type) can point to objects of different types. To
me it is the nature of the pointer/reference that is changing not the
nature of the pointee or referent.
Scott Meyers uses this terminology in his Effective C++ (or More EC++,
not sure which one).
I think it's one of those "catch 22" situations --- either way that
we try to say it can be questionable if we get picky enough. For
example, when you say that "whatever is being pointer at will not
change its type", that could (and IMO should) be questioned: if
you see "whatever is pointed at" as a variable (in the sense of a
*mathematical variable*), as I think it *should* be, then of course
it changes!
I think the crucial argument (and I hope I'm getting the basics
right) is that in a declaration "T * ptr", the type of the pointer
is T (I seem to recall reading this in, maybe, TC++PL, when Stroustrup
argues about the marits of putting the space between the T and the *
vs between the * and the variable name).
But either way, an argument in the way of trying to convince Dave
about this terminology is that the type of the object pointed at is
definitely an attribute of the pointer, and when polymorphism is
involved, then there are two facets for that: the type of the
pointed object as declared, and the type of the object at which
the pointer is pointing at a given pointy in time during execution
(which can change). Thus the names "static type" and "dynamic type"
*for the pointer*.
to.
'dynamic type of *p' is well formed terminology according to standard.
if that pointer object is being referred to.
read [defns.dynamic.type].
[ comp.lang.c++.moderated. First time posters: Do this! ]