Question OOP-ABS-0040
EasyWhat is the output of this code?
#include <iostream>
using namespace std;
struct Shape {
virtual int sides() = 0;
virtual ~Shape() {}
};
struct Tri : Shape { int sides() override { return 3; } };
struct Quad : Shape { int sides() override { return 4; } };
int main() {
Shape* s[] = { new Tri(), new Quad(), new () };
t = ;
(Shape* x : s) {
t += x->();
x;
}
cout << t;
}
- A.
9
- B.
12
- C.
Sign up free to see the answer and a step-by-step explanation.