Topic: abstract class questions


Author: clamage@taumet.eng.sun.com (Steve Clamage)
Date: 1996/09/06
Raw View
Hello,

Reading the April 95 WP I have not found the explicit answer for
two questions about abstract classes.
1) Is it possible to apply to the `sizeof' for the abstract class
   or a reference to abstract class ?
2) Is it possibale to apply unary `*' operator for the pointer to
   abstract class ? (Is it ok to use such application same way as
   unary `*' for incomplete type ?)

Thank you in advance,
--
Alexander N. Krotoff
Research Computer Center
Moscow State University


[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: sj@aracnet.com (Scott Johnson)
Date: 1996/09/06
Raw View
In article <199609061452.RAA02042@such.srcc.msu.su>,
Steve Clamage <clamage@taumet.eng.sun.com> wrote:
>Hello,
>
>Reading the April 95 WP I have not found the explicit answer for
>two questions about abstract classes.
>1) Is it possible to apply to the `sizeof' for the abstract class
>   or a reference to abstract class ?

Yup and yup, although the latter is cause for debate.  (Not whether or not
you can do it..you can...but whether doing sizeof on a reference should
return the size of the underlying pointer, or the referred-to class.  This
debate has nothing to dowhether or not the class is abstract, BTW)





>2) Is it possibale to apply unary `*' operator for the pointer to
>   abstract class ? (Is it ok to use such application same way as
>   unary `*' for incomplete type ?)

No problem at all in dereferencing a pointer to an abstract base class.
It won't point to an instance of the ABC, but it will point to an instance
of a DERIVED class, and will access all of the derived class's methods,
instead of the base class's methods.

It's done all the time, and is one of the kay features of C++.


BTW; abstract classes are "complete".  You just cannot instantiate
one--that is the only difference.

Scott


--
/--------------------------------------------------------------------------\
|Scott Johnson -- Professional (sometimes) SW Engineer and all-purpose Geek|
|I don't speak for nobody but myself, which everyone else is thankful for  |
\--------------------------------------------------------------------------/

[Moderator's note: the quoted text wasn't actually written by Steve
Clamage.  It appeared to be his because of a software quirk.  mha]
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]