The Slicing Problem

Medium Polymorphism & Function Overloading
Solve in Playground →

Problem Statement

Create `Base` (virtual `void show()` printing ‘Base’) and `Derived` (overriding `show()` to print ‘Derived’). Write a global function `void displayValue(Base b)` that takes a Base object by VALUE. In `main()`, instantiate `Derived` and pass it to `displayValue`. Observe the output.

Input Format

None

Output Format

Print the message triggered by the value-passed object.

Constraints

None

Sample Output

Base

Explanation

Passing a derived object by value slices off its derived properties and destroys polymorphism. To maintain polymorphic behavior, objects must be passed by pointer or reference.

Starter Code

#include <iostream>

class Base {
public:
    // Implement virtual show
};

class Derived : public Base {
public:
    // Override show
};

// Write displayValue passing Base by value

int main() {
    // Instantiate Derived, pass to displayValue
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used