This paper describes an algorithm for slicing class hierarchies in C+ programs. Given a C++ class hierarchy (a collection of C++ classes an
d inheritance relations among them) and a program P that uses the hier
archy, the algorithm eliminates from the hierarchy those data members,
member functions, classes, and inheritance relations that are unneces
sary for ensuring that the semantics of P is maintained. Class slicing
is especially useful when the program P is generated from a larger pr
ogram P' by a statement slicing algorithm. Such an algorithm eliminate
s statements that are irrelevant to a set of slicing criteria-program
points of particular interest. There has been considerable previous wo
rk on statement slicing, and it will not be the concern of this paper.
However, the combination of statement slicing and class slicing for C
++ has two principal applications: First, class slicing can enhance st
atement slicing's utility in program debugging and understanding appli
cations, by eliminating both executable and declarative program compon
ents irrelevant to the slicing criteria. Second, the combination of th
e two slicing algorithms can be used to decrease the space requirement
s of programs that do not use all the components of a class hierarchy.
Such a situation is particularly common in programs that use class li
braries.