Array of Base Class Pointers

Medium Virtual Functions & Abstract Classes
Solve in Playground →

Problem Statement

Create an abstract `Worker` class with `virtual void work() = 0;`. Create `Developer` printing ‘Coding’ and `Manager` printing ‘Managing’. In `main()`, create an array of two `Worker*` pointers containing one of each. Loop through the array and call `work()` on both.

Input Format

None

Output Format

Print each worker's task on a separate line.

Constraints

None

Sample Output

Coding
Managing

Explanation

Abstract base pointers allow creating polymorphic collections where you iterate through different types of objects with identical interfaces.

Starter Code

#include <iostream>

class Worker {
public:
    // Pure virtual method
};

class Developer : public Worker {
public:
    // Override
};

class Manager : public Worker {
public:
    // Override
};

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