delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/11/13:56:24

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A pointer of variable type - is it possible?
Date: Fri, 11 Oct 1996 08:45:00 -0700
Organization: Alcyone Systems
Lines: 42
Message-ID: <325E6B7C.41340651@alcyone.com>
References: <982A4C7275 AT fs2 DOT mt DOT umist DOT ac DOT uk>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

A.Appleyard wrote:

>   If you define these codes:-
>   enum{_unknown=0, _spaceship=1, _star=2, _missile=3; .....};
>   and if you make sure that spaceship.sort==1, star.sort==2, etc, always,
>   then (I think) you can convert back:-
>
>  switch(X.sort) {
>   case _spaceship: S=(spaceship*) X; .... handle a spaceship ....; break;
>   case _star:      C=(star*)      X; .... handle a star      ....; break;
>   etc etc;};

If you're doing this, then you're not taking advantage of object-oriented
programming correctly.

Consider;  Under what cases would you need to do this case-by-case
breakdown of the behavior of specific (i.e., derived) objects?  What you
should be doing is wrapping _those_ actions in a virtual member function
which is overridden in subsequently derived classes.

So in the case of the example you give, you'd have an Object::Handle member
function, which would be overridden by each of the derived classes.  In
_these_ is where object-specific code would occur, not in some global
function which breaks down the individual objects case by case.

Generally if you find yourself in a situation where you think you have to
do this kind of thing to get around a problem, it means you're not using
object-oriented design properly -- you should rethink your class hierarchy
and how the different classes interact with one another.

>    What's a signature? What variant of C does it occur in?

Signatures are a gcc-specific C++ extension.  Come to think of it, it may
be in one of the newer draft standards (I know there have been papers on
it), but I don't know how well the idea is accepted in the C++ community
offhand.

-- 
                             Erik Max Francis | max AT alcyone DOT com
                              Alcyone Systems | http://www.alcyone.com/max/
                         San Jose, California | 37 20 07 N 121 53 38 W
                                 &tSftDotIotE | R^4: the 4th R is respect

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019