Function Template Instances
Table of Contents


C++ does not compile the template function directly. Instead, at compile time, when the compiler encounters a call to a template function, it replicates the template function and replaes the template type paraemter with actual types. The function is actual types is called a function template instance.


Example 1:

class Cents
    int m_Cents;
    Cents (int nCents) : m_Cents(nCents)
    { }
//we need to overload the > operator to use max()
  friend bool operator>(Cents &c1, Cents &c2)
      return (c1.m_Cents > c2.m_Cents) ? true:false;
int main()
  Cents cNickle(5);
  Cents cDime(10);
  Cents cBigger = max(cNickle, cDime);      
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.