Re: c++ inheritance

ltd@netcom.com (Larry Drebes)
Sat, 13 Nov 1993 17:34:18 GMT

          From comp.compilers

Related articles
Re: c++ inheritance bejenari@latcs1.lat.oz.au (1993-11-12)
Re: c++ inheritance ltd@netcom.com (1993-11-13)
| List of all articles for this month |

Newsgroups: comp.compilers
From: ltd@netcom.com (Larry Drebes)
Keywords: C++
Organization: Chaos
References: 93-11-076
Date: Sat, 13 Nov 1993 17:34:18 GMT

: W(a,b,c,d)
: |
: X
: |
: Y
: |
: Z(a,b,c,d)




: Q1 : If classes X and Y don't need/want properties (a,b,c,d) do they have
: to inherit them ?


Yes. In C++, a class is an interface definition. When you inherit that
definition you get the whole interface. With that inherited interface you
can hide (although not on an individual basis), and/or override members
by supplying a new one.


Perhaps in your example W should be composed of W1 & W2 where X & Y only
need the goods in W1.


: Q2 : Will any changes to (a,b,c,d) lead to the intermediate classes(X, Y)
: being recompiled ?


If (a,b,c,d) are purely member functions (ie code, not data) and the
change does not need to change the interface (ie the parameters or return-
values do not change), then only the changed code need be recompiled.


If a change to (a,b,c,d) changes the interface to class W, then all code
using W,X,Y & Z should be recompiled. Hopefully by nature of your
development environment, but it is absolutely in the interest of code
correctness. There are times when heuristics might prove you could skip
compiling a certain module for a particulare modification of a C++ class
definition, but when you start playing those games you will almost always
shooting yourself in the foot at some later date by linking with something
obsolete.


The accepted C++ practice is to put the class definition in a header and
include that header in any module/header that needs that class. The
makefile should have the dependencies so when you change that header (even
to add a comment) it should re-compile everyone who includes it.


: Q3 : Would it be reasonable to expect that classes X and Y should not be
: recompiled because they don't need to ?


It's the same reasoning when you have some header file that is included in
each of 100 .c files, and you go to change a #define in that header file
knowing that the value is only used in 10 of those .c files.


: Q4 : Is it a big issue that the intermediate classes get recompiled in
: large projects, when the compilation time may be an important issue ?


Yes. The solution in current times is an interpreted environment like
centerline or faster hardware.


: Q5 : How do I find out more about how particular compilers handle the
: storage mechanism and typing model used in implementing inheritance, and
: also is there any literature that deals with the situation in Q3 and Q4 ?


Get the ARM, read it several times. Although terse, it does contain the
blueprint for what a compiler must provide, what is implemenation
specific, and in general the method to the madness.


larry-
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.