Another C++ class template explicit instantiation 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++ class template explicit instantiation in C++ programming

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

 

// the C++ explicit instantiation

#include <iostream>

using namespace std;

 

template <class any_data_type>

any_data_type Test(any_data_type Var1)

{

return Var1;

}

// an explicit instantiation of Test(int)

template int Test<int>(int);

 

// do some testing

int main(void)

{

cout<<"Var1 = "<<Test(100)<<endl;

return 0;

}

 

Output examples:

 

Var1 = 100

Press any key to continue . . .

 

 

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