Class template declarations and definitions (C++ only)
A class template must be declared before any instantiation of a corresponding template class. A class template definition can only appear once in any single translation unit. A class template must be defined before any use of a template class that requires the size of the class or refers to members of the class.
template <class L> class Key; // class template declared,
// not defined yet
//
class Key<int> *keyiptr; // declaration of pointer
//
class Key<int> keyi; // error, cannot declare keyi
// without knowing size
//
template <class L> class Key // now class template defined
{ /* ... */ };
If a template class is used before the corresponding class template is defined, the compiler issues an error. A class name with the appearance of a template class name is considered to be a template class. In other words, angle brackets are valid in a class name only if that class is a template class.
template <class L> class Key; // class template declared,
// not defined yet
//
Key<int> *keyiptr; // declaration of pointer
//
Key<int> keyi; // error, cannot declare keyi
// without knowing size
//
template <class L> class Key // now class template defined
{ /* ... */ };
In the z/OS® implementation, the compiler checks the syntax of the entire template class definition when the template include files are being compiled if the TEMPINC compiler option is used, or during the original compiler pass if the NOTEMPINC compiler option is used. Any errors in the class definition are flagged. The compiler does not generate code or data until it requires a specialization. At that point it generates appropriate code and data for the specialization by using the argument list supplied.