Skip to content
Quiz · Classes and OOP · lesson 12 of 15

Quiz — what override checks

What happens when you build and run this program?

C++
#include <iostream>

struct Base {
    virtual void print(int x) const { std::cout << "Base " << x; }
};
struct Derived : public Base {
    void print(long x) const override { std::cout << "Derived " << x; }
};

int main() { Derived d; const Base& b = d; b.print(1); }

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way