Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Viewing all articles
Browse latest Browse all 223

Answer by Peter - Reinstate Monica for Inheritance in C++ for a class project

$
0
0

One traditional reason inheritance was invented was to re-use code in base classes. Client has an input operator; the input operator for the derived class Campaign should first call the input operator for the Client base class, re-using that existing code, and then prompt for the data members added in the derived class. This mimics the way constructors work, "inside-out"; but as opposed to compiler-generated constructors, you have to explicitly code that with an input function.

Whether that design is good is a different question; in the past two or three decades this kind of relative strong coupling has lost its appeal (and, for example, inheritance is often replaced with injection/membership).


Viewing all articles
Browse latest Browse all 223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>