Re: ((Object *)NULL)->MemberFunction();
This is a MIME GnuPG-signed message. If you see this text, it means that
your E-mail or Usenet software does not support MIME signed messages.
The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
To open this message correctly you will need to install E-mail or Usenet
software that supports modern Internet standards.
--=_mimegpg-commodore.email-scan.com-4212-1204428688-0001
Content-Type: text/plain; format=flowed; charset="US-ASCII"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Ian Collins writes:
Kai-Uwe Bux wrote:
Ian Collins wrote:
jason.cipriani@gmail.com wrote:
Sorry about the subject but it's the most descriptive thing I came up
with. Is something like this safe to do:
// all objects let you get some string ID
class BaseObject {
public:
virtual const char * GetID (void) const;
Drop the C style void,
virtual const char* GetID() const = 0;
Is correct and idiomatic C++.
Well,
virtual const char * GetID (void) const = 0;
is correct C++, too.
If not idiomatic. The void serves a purpose in C, but not in C++.
return ((T *)NULL)->GetID();
}
This can not work for polymorphic objects. The object has to be
properly constructed in order to call a virtual method.
The code dereferences a null pointer. It has undefined behavior regardless
of whether the method is virtual or not and of whether the the "object"
(which does not exist) is polymorphic or not.
True, but it falls into the "probably works" box for normal member
functions that don't access any data members. But yes, it is a bad
thing to do.
It will /never/ work. Why? Because GetID() is a virtual function. Think
about it.
--=_mimegpg-commodore.email-scan.com-4212-1204428688-0001
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
iD8DBQBHyh+Qx9p3GYHlUOIRAo5EAJ0cSMYV5hyYYJJhB6sRJFExjDjkkQCfXJOu
/zFSSi1guB/uIyPiJDqAaWc=
=xG8Z
-----END PGP SIGNATURE-----
--=_mimegpg-commodore.email-scan.com-4212-1204428688-0001--