Chapter 10. Template Specialization and Overloading

Difficulty: 6

How do you specialize and overload templates? When you do, how do you determine which template gets called? Try your hand at analyzing these 12 examples.

  1. What is template specialization? Give an example.

  2. What is partial specialization? Give an example.

  3. Consider the following declarations:

    template<typename T1, typename T2>
    void g( T1, T2 );                       // 1
    template<typename T> void g( T );       // 2
    template<typename T> void g( T, T );    // 3
    template<typename T> void g( T* );      // 4
    template<typename T> void g( T*, T );   // 5
    template<typename T> void g( T, T* );   // 6
    template<typename T> void g( int, T* ); // 7
    template<> void g<int>( int );          // 8
    void g( int, double );                  // 9
    void g( int );                          // 10
    

    Which ...

Get More Exceptional C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.