Skills101
← All practice quizzes

Quiz: Operators and Templates

5 questionsNo time limitPass: 60%+10 XP on first pass

Make your classes work with +, ==, << and more, use friend functions correctly, and write generic code once with function and class templates.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    Why is operator<< usually a non-member (often friend) function?

  2. Question 2

    Which operator can NOT be overloaded in C++?

  3. Question 3

    What does this print?

    #include <iostream>
    using namespace std;
    template <typename T>
    T twice(T x) { return x + x; }
    int main() {
        cout << twice(21) << " " << twice(1.5);
        return 0;
    }
    
  4. Question 4

    Is friendship inherited by derived classes?

  5. Question 5

    What is vector<int> an example of?