Another working implicit class template instantiation C++ code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Creating and using the C++ implicit class template instantiation in C++ programming

To show: How  to create and use the implicit class template instantiation in C++ programming

 

// another C++ implicit template instantiation example

#include <iostream>

using namespace std;

 

template <class any_data_type>

any_data_type MyMax(any_data_type Var1, any_data_type Var2)

{

return Var1 > Var2 ? Var1:Var2;

}

 

// do some testing

int main(void)

{

int p;

char q;

 

p = MyMax(100, 200);

q = MyMax('k', 'K');

 

// implicit instantiation of MyMax(int, int)

cout<<"MyMax(100, 200) = "<<p<<endl;

// implicit instantiation of MyMax(char, char)

cout<<"MyMax('k', 'K') = "<<q<<endl;

return 0;

}

 

Output examples:

 

MyMax(100, 200) = 200

MyMax('k', 'K') = k

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index