6.2.4 Class Template Use
A template class can be used wherever a type can be used. Specifying
a template class consists of providing the values for the template name and
arguments. The declaration in the following example creates the variable int_array based upon the Array template. The
variable’s class declaration and its set of methods are just like those
in the Array template except that Elem is
replaced with int (see 6.3 Template Instantiation).
Array<int> int_array(100);
|
The declaration in this example creates the short_string variable
using the String template.
String<8> short_string("hello");
|
You can use template class member functions as you would any other member
function
int x = int_array.GetSize( );
|
int x = short_string.length( );
.
|