Re: Abandonment of aggregate types
truedfx@gmail.com (Harald van D=FE=FF_3k) writes:
Dave Steffen wrote:
giecrilj@stegny.2a.pl ("Kristof Zelechovski") writes:
Uzytkownik "Dave Steffen" <dgsteffen@numerica.us> napisal w wiadomos=
ci
news:qqmwt99pyia.fsf@yttrium.numerica.us...
skaller <skaller@users.sourceforge.net> writes:
On Tue, 15 Aug 2006 14:00:18 +0000, Dave Steffen wrote:
fgothamNO@SPAM.com (Frederick Gotham) writes:
[...]
Well, "farce" might be a little harsh. Constructors are clean a=
nd
built in;
Huh? they actually allow you to break the type system without
casting (store non-const pointer to const object).
I'm not sure why you think that breaks the type system. Adding
const-ness to something doesn't break anything IMHO. Do you have=
an
[...]
class T {
public:
T(T *&p_t) { p_t = this; }
int m;
};
int main() {
T *p_t;
const T t(p_t);
p_t->m = 0; // oops!
}
OK, but I still don't see why this is an example of "constructors
breaking the type system". IANALanguageL, but I don't think
that 'const' applies during construction. I would also opine that is
is a silly, or at least strange, piece of code to write. We all know
that most of the protections and restrictions designed into C++ are
designed to guard against Murphy, not against Machiavelli (I'm pretty
sure Dr. Stroustrup said that).
How is this any worse than
int* ip = new int(3);
const int* const_ip = ip;
*ip = 42; // what happened to my const data?
Agreed, your example is less obvious than this example, or the usual
'cast-away-constness-and-lie-to-the-compiler' tricks seen on the
other newgroups so often; but you're reaching into an object during
construction and returning a pointer to its internal data. Don't Do
That.
I continue to refute the statement made earlier by "skaller", in
response to my statement that constructors are clean, where he said
Huh? they actually allow you to break the type system without
casting (store non-const pointer to const object).
By your example, they only allow this sort of bad behavior when
explicitly told to do so (against all guidelines I know of). I hold
that this is less egregious than many other, much more problematic
issues (such as the issues raised by Frank Gotham that started this
thread).
I'd also ask if you, or skaller, have any suggestions on how to fix
your example; how, for example, would you change the syntax of the
language to dissalow your example?
----------------------------------------------------------------------
Dave Steffen, Ph.D.
Software Engineer IV Disobey this command!
Numerica Corporation - Douglas Hofstadter
dgsteffen at numerica dot us
---
[ 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://www.comeaucomputing.com/csc/faq.html ]