Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!brutus.cs.uiuc.edu!jarthur!uci-ics!ics.uci.edu!rfg From: rfg@ics.uci.edu (Ron Guilmette) Newsgroups: comp.lang.c++ Subject: Objects of type ????? Message-ID: <25955350.5608@paris.ics.uci.edu> Date: 24 Dec 89 22:53:04 GMT Reply-To: rfg@ics.uci.edu (Ron Guilmette) Organization: University of California, Irvine - Dept of ICS Lines: 47 In the new C++ Reference Manual, it is stated that: "An abstract class is a class that can only be used as a base class of some other class; no objects of an abstract class may be created EXCEPT AS SUB-OBJECTS OF SOME OTHER CLASS". (The added emphasis is mine.) It is that last part that has me really confused. Can sombody please tell me how (or why) it makes any sense to allow this exception to the (otherwise reasonable) rule? The first part of the rule is reasonable because it attempts to insure that objects of an abstract class (which is essentially an incomplete thing) are not accidently created. However the exception allowed for "sub-objects" of other objects seems to make the whole rule pointless, because you can now circumvent the general rule and create objects of type . A simple example of the problems that this "exception" to the general rule can cause is illustrated below: struct abstract { virtual void foobar () = 0; }; struct concrete { abstract abstract_member; }; concrete concrete_object; main () { concrete_object.foobar (); // is this legal ???? } Note that the call to foobar() within main() is certain to be invalid, and will generally cause a segfault. So what's going on here? It seems that the declaration of objects of abstract types should be either always allowed or never allowed. Having it be "sometimes" allowed just doesn't make sense to me. // rfg