Will the following code compile?
template<typename T> class  A{ A(){} };    // 1

template<typename T> struct B{ B(){} };    // 2

template<typename T> union  C{ C(){} };    // 3

template<template<typename> class U, typename V>
struct D
{
    D()
    {
        U<V> u;
    }
};

int main()
{
    D<A, int> a;    // 4
    D<B, int> b;    // 5
    D<C, int> c;    // 6
}
Explanation
In line 4, when creating an object a, the protected constructor of class A is called (by default, class members have private access modifier, and members of structures and unions are public).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes