Template Inheritance Chain
Using the definitions below, what is the combined output of these three lines?
#include <iostream>
#include <string_view>
template <typename Type>
struct X {
void bar() { std::cout << Type::identify(); }
static std::string_view identify() { return "X"; }
};
template <typename Type>
struct Y : Type {
void bar() { std::cout << Type::identify(); }
static std::string_view identify() { return "Y"; }
};
class Z {
protected:
void bar() { std::cout << identify(); }
static std::string_view identify() { return "Z"; }
};
int main() {
Y<Z>{}.bar();
X<Y<Z>>{}.bar();
Y<X<Y<Z>>>{}.bar();
}
Sign in to answer questions and track your progress
Sign In