Function Syntax Explicit Specialization

Based on the textbook ,

// Example 2: Explicit specialization 
// 
template<class T> // (a) a base template 
void f( T ){;}

template<class T> // (b) a second base template, overloads (a) 
void f( T* ){;}     //     (function templates can't be partially 
//     specialized; they overload instead)

template<>        // (c) explicit specialization of (b) 
void f<>(int*){;} // ===> Method one

I am also testing the following with VS2010 SP1 without warning.

template<>        // (c) alternative
void f<int>(int*){;} // ==> Method two

Question What method is recommended to use based on the C ++ standard? Method one or two methods?

As you can see, the key, different from the first method and method two, is as follows:

template<>        
void f<>(int*){;}    // ===> Method one

template<>        
void f<int>(int*){;} // ===> Method two
       ^^^

Based on the tutorial, we should write the following regular old function:

void f(int*){;}

But this is NOT the question I ask :)

thank

+3
source share
1 answer

, ( ) . [from "++ " Vandervoode, Josuttis]

, :

template<>
void f(int){;}

(a)

template<>
void f(int*){;}

(b).

+1

All Articles