110. Name Hiding in Inheritance

#include <iostream>
using namespace std;

// Base driver class
class BaseDriver {
public:
    void configure(int value) {
        cout << "Base configuration value " << value << endl;
    }
};

// Derived driver class
class DerivedDriver : public BaseDriver {
public:
    using BaseDriver::configure;  // Restore base class overload

    void configure() {
        cout << "Derived default configuration" << endl;
    }
};

int main() {
    int value;
    cin >> value;

    DerivedDriver driver;
    driver.configure();        // Derived version
    driver.configure(value);   // Base version

    return 0;
}

Explanation & Logic Summary:

When a derived class defines a function with the same name as a base class function, all base class overloads with that name are hidden.

The statement:

using BaseDriver::configure;

explicitly brings the base class function back into the derived class scope, allowing both overloads to coexist and be called on the same object.

Firmware Relevance & Real-World Context:

In real embedded firmware:

  • Base drivers expose low-level, parameterized configuration hooks
  • Derived drivers provide default or simplified APIs
  • Name hiding can silently disable critical base functionality

Failing to address this can lead to:

  • Incomplete hardware initialization
  • Incorrect peripheral configuration
  • Hard-to-diagnose runtime bugs

Understanding and resolving name hiding is essential for building safe, extensible, and maintainable embedded driver hierarchies.

 

 

 

 

Loading...

Input

8

Expected Output

Derived default configuration Base configuration value 8