21. Private Inheritance

#include <iostream>
using namespace std;

class Device {
public:
    void showType() {
        cout << "Generic Device\n";
    }
};

class Actuator : private Device {
public:
    void showActuator() {
        showType();
        cout << "Actuator Device\n";
    }
};

int main() {
    Actuator a;
    a.showActuator();
    return 0;
}


Solution Explanation

  • Private inheritance makes showType() completely hidden from outside.
  • The derived class can still call it, but nothing outside the class hierarchy can.

     

Layman’s Terms

It’s like a secret tool in a locked drawer — only the device itself uses it, and no one else can even see it.


Significance for Embedded Developers

Private inheritance can model “implemented in terms of” relationships. For instance, a higher-level actuator class might reuse a low-level device API internally, without exposing it publicly.
 

Loading...

Input

Expected Output

Generic Device Actuator Device