Pointers to Base Class holding Derived Objects

Hard Polymorphism & Function Overloading PRO
🔒 Login to Unlock

Problem Statement

Create a `Vehicle` base class with a `virtual void move()` printing ‘Moving’. Create `Car` (‘Driving’) and `Bike` (‘Riding’). In `main()`, create an array of `Vehicle*` pointers. Assign a `Car` and a `Bike` object to the array indices. Loop through the array and invoke `move()`.

Input Format

None

Output Format

Print the specific movement messages in sequence.

Constraints

Array size is 2.

Sample Output

Driving
Riding

Explanation

Arrays of base class pointers allow unified collections of diverse derived objects, iterating and triggering polymorphic behaviors seamlessly.

Starter Code

#include <iostream>

class Vehicle {
public:
    // Implement virtual move
};

class Car : public Vehicle {
public:
    // Override move
};

class Bike : public Vehicle {
public:
    // Override move
};

int main() {
    // Setup array of pointers and iterate
    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