Templates

16.Can you pass a template type to another template?
  • A. No, templates cannot be passed to other templates
  • B. Yes, it is called a template template parameter
  • C. Only primitive types can be passed to templates
  • D. Templates can only be passed to functions, not to classes

Yes, it is called a template template parameter

Yes, it is called a template template parameter

17.What is the correct syntax for a template function with two template parameters?
  • A. template <typename T, typename U> void func(T, U);
  • B. template <T, U> void func(T, U);
  • C. template <class T, class U> void func(T, U);
  • D. template <typename T = int, typename U> void func(T, U);

template <typename T, typename U> void func(T, U);

template <typename T, typename U> void func(T, U);

18.How can you make a class template accept only certain types?
  • A. By using a type trait
  • B. By specifying a list of acceptable types in the template
  • C. By adding a static_assert in the constructor
  • D. By using a template specialization for each type

By using a type trait

By using a type trait

19.What is an example of a non-type template parameter?
  • A. template <int N> void func() {}
  • B. template <typename T> void func(T t)
  • C. template <class T> void func() {}
  • D. template <auto T> void func() {}

template <int N> void func() {}

template <int N> void func() {}

20.What happens if you use a non-type template parameter with a floating-point type?
  • A. It will cause a compile-time error because floating-point types cannot be used as non-type template parameters
  • B. It works as expected
  • C. Only integral types are allowed for non-type template parameters
  • D. The program will run without issues, but with lower performance

It will cause a compile-time error because floating-point types cannot be used as non-type template parameters

It will cause a compile-time error because floating-point types cannot be used as non-type template parameters