Re: Dereferencing a null-pointer allowed?
On May 10, 3:06 pm, Ron Natalie <r...@spamcop.net> wrote:
James Kanze wrote:
With one important exception, I believe: if the expression is
used as an argument to sizeof or typeid. Something like:
sizeof( ((T*)0)->f() )
is legal, I think.
Correct, sizeof doesn't evaluate it's argument, it merely
checks the type.
Typeid does however potentially do so, since the result
may be something it has to test the dynamic typing of.
Good point. But if I understand ?5.2.8 correctly, this can only
happen in a case like the above if the return value is a
reference to a type having at least one virtual function. (Of
course, if I know the type, and it cannot be polymorphic, what's
the point of using typeid?) It's interesting to note that this
depends only on the return type of T::f()---whether T::f() is
virtual or not plays no role in the issue.
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:email@example.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]