An Inheritance Example with Dynamic Memory Allocation and Friends

To illustrate these ideas of inheritance and dynamic memory allocation, let’s integrate the baseDMA, lacksDMA, and hasDMA classes just discussed into a single example. Listing 13.14 is a header file for these classes. To what we’ve already discussed, it adds a friend function that illustrates how derived classes can access friends to a base class.

Listing 13.14. dma.h

// dma.h  -- inheritance and dynamic memory allocation#ifndef DMA_H_#define DMA_H_#include <iostream>//  Base Class Using DMAclass baseDMA{private:    char * label;    int rating;public:    baseDMA(const char * l = "null", int r = 0);    baseDMA(const baseDMA & rs);    virtual ~baseDMA();    baseDMA & operator=(const ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.