Question 6
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
struct I1 { virtual void a() = 0; virtual ~I1() = default; };
struct I2 { virtual void b() = 0; virtual ~I2() = default; };
struct One : I1 { void a() override {} };
struct Two : I1, I2 { void a() override {} void b() override {} };
int main() {
std::cout << sizeof(I1) << ' ' << sizeof(One) << ' ' << sizeof(Two) << '\n';
return 0;
}
- A 8 8 16 Correct
- B 8 8 8
- C 0 8 16
- D 8 16 24
Correct Answer: Option A
Each polymorphic base subobject needs its own vptr, so implementing two interfaces costs two pointers.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!