Object Slicing
What is the output of this code?
#include <iostream>
class Base {
public:
virtual std::string name() { return "Base"; }
};
class Derived : public Base {
public:
std::string name() override { return "Derived"; }
};
int main() {
Derived d;
Base b = d; // copy
std::cout << b.name();
}
Sign in to answer questions and track your progress
Sign In