Templates
21.How do you prevent a template class from being instantiated with a certain type?
-
A. By using template specialization
-
B. By making the class template private
-
C. By using static_assert inside the class template
-
D. By defining a delete function inside the class
By using static_assert inside the class template
By using static_assert inside the class template
22.What is the output of the following code?
template
void func(T x) {
std::cout << x << std::endl;
}
int main() {
func(5); // Output: ?
}
-
A. 5
-
B. Undefined behavior
-
C. "int"
-
D. Error
5
5
23.What does SFINAE stand for in C++ templates?
-
A. Syntax For Inherited Abstract Expressions
-
B. Substitution Failure Is Not An Error
-
C. Specialization For Internal Aggregate Expressions
-
D. Static Function Insertion And Execution
Substitution Failure Is Not An Error
Substitution Failure Is Not An Error
24.Which of the following is an example of using SFINAE?
-
A. template <typename T> typename std::enable_if<std::is_integral<T>::value>::type func(T);
-
B. template <typename T> void func(T) = 0;
-
C. template <typename T> void func() {}
-
D. template <typename T> void func(T) {}
template <typename T> typename std::enable_if<std::is_integral<T>::value>::type func(T);
template <typename T> typename std::enable_if<std::is_integral<T>::value>::type func(T);
25.Which of the following is true about a template alias?
-
A. It is a synonym for a template class or function
-
B. It creates a new type entirely
-
C. It is used for template specialization
-
D. It is an advanced form of template metaprogramming
It is a synonym for a template class or function
It is a synonym for a template class or function