Multiple Choice Quiz

1. How does the keyword mutable modify a lambda?

2. Which of the following is only allowed to appear once in a single translation unit?

3. Consider the function template:
  template <typename T>
  void process(T&& arg) { /* ... */ }
If an lvalue int a is passed to process, what type is deduced for T?

4. What does it mean for a lambda to be "generic"?

5. Consider the following function template that takes in a container and returns its size as a double:
  template <typename T>
  double dsize(const T & container) {
    return static_cast<double>( container.size() );
  }
When the compiler first encounters this template (before instantiation with a specific type for T), it checks any aspects that it can for syntax correctness. Which of the following aspects will NOT be checked until the template is instantiated with a specific type for T?

6. Consider this code:
  template <typename T=int>
  T getValue() {
      return T();
  }
What will getValue() return if called without any arguments?

7. What is the difference between template parameters and template arguments?

8. Given the following function template:
  template <typename T>
  void Print(const T & item) {
    std::cout << item << std::endl;
  }
Which call to Print would cause a compile-time error?

9. What is an explicit specialization of a template?

10. Which of that following is a potential downside of excessive use of templates, even when fully adhering to the C++ standard?


Click Check Answers to identify any errors and try again. Click Show Answers if you also want to know which answer is the correct one.