Question 5
Back to Exercise
What is the output of the following C++ program on a 64-bit system?
#include <iostream>
#include <type_traits>
struct A { virtual void f() = 0; virtual void g() = 0; virtual ~A() = default; };
struct B : A { void f() override {} };
struct C : B { void g() override {} };
struct D : C { void f() override = 0; }; // re-declared pure!
struct E { virtual void h() {} };
int main() {
std::cout << std::is_abstract_v<A> << std::is_abstract_v<B> << std::is_abstract_v<C>
<< std::is_abstract_v<D> << std::is_abstract_v<E> << '\n';
return 0;
}
- A 11010 Correct
- B 11000
- C 10010
- D 11110
Correct Answer: Option A
B misses g(); C is concrete; D overrides f() as pure again, making it abstract; E has virtual functions but none pure.
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!