RAD Studio
ContentsIndex
PreviousUpNext
Class Templates Overview

This section contains Class Templates Overview topics.

Name 
Description 
Be careful when using the right angle bracket character upon instantiation:  
Multiple arguments are allowed as part of the class template declaration. Template arguments can also represent values in addition to data types:  
A class template (also called a generic class or class generator) lets you define a pattern for class definitions. Consider the following example of a vector class (a one-dimensional array). Whether you have a vector of integers or any other type, the basic operations performed on the type are the same (insert, delete, index, and so on). With the element type treated as a type parameter to the class, the system will generate type-safe class definitions on the fly.
As with function templates, an explicit template class specialization can be provided to override the automatic definition for a given type:... more 
Another design technique is to include actual objects, making pointers unnecessary. This can also reduce the number of virtual function calls required, since the compiler knows the actual types of the objects. This is beneficial if the virtual functions are small enough to be effectively inlined. It's difficult to inline virtual functions when called through pointers, because the compiler doesn't know the actual types of the objects being pointed to.  
In general, when you need to write lots of nearly identical things, consider using templates. The problems with the following class definition, a generic list class,  
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!