Templates

11. What is a template specialization in C++?
  • A. A function that works only with a particular type
  • B. A way to create different implementations for specific types
  • C. A mechanism to define template variables
  • D. A type of inheritance mechanism

A way to create different implementations for specific types

A way to create different implementations for specific types

12.Which of the following is correct regarding function template overloading?
  • A. Templates cannot be overloaded
  • B. Function templates can be overloaded based on parameter types
  • C. Only template classes can be overloaded
  • D. Template function overloading is always illegal in C++

Function templates can be overloaded based on parameter types

Function templates can be overloaded based on parameter types

13.What is the syntax for defining a template function that accepts two parameters of the same type?
  • A. template <typename T> void func(T, T);
  • B. template <typename T> void func(T, T = 0);
  • C. template <T> void func(T, T);
  • D. template <class T> void func(T, T);

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

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

14.How do you instantiate a template function with a specific type?
  • A. func<int>();
  • B. func<T>();
  • C. T func();
  • D. template <int> func();

func<int>();

func<int>();

15. What will happen if you use a template class without defining the type?
  • A. The compiler will choose the best type for you
  • B. It will cause a compile-time error
  • C. The class will work with all types
  • D. The program will run without issues

It will cause a compile-time error

It will cause a compile-time error