You can use a class to create a template class. In addition, some template parameters can be specified as specific types and a specialized function to create a specialization or new class/function with content that is unrelated to the original template.
About this task
You can useIBM® Rational® Rhapsody® DiffMerge to locate and merge template information.
Procedure
- Double-click the class in the IBM Rational Rhapsody browser to open its Features window.
- On the General tab, in the Class Type area, select the Template radio button.
Notice that the Template Parameters tab displays.
- On the Template Parameters tab, click <new>.
- Type a name to replace the default name that the product creates as <class_n>.
- Accept the default type or select another one from the Kind list.
- To add arguments for the template, click the Invoke Feature Dialog button
to open the Template Argument window. Note the following information about the Template Argument window: - If you select the Use existing type check box, you can change the type and enter a description. In C++, you can also provide a default value for the template argument.
- If you clear the Use existing type check box, you can enter code that further refines the argument type, for example a pointer to a type or an array of a certain type. When entering code in the C++[Java] Declaration field, you can also see other arguments that have been defined.
- Click OK to close the Template Argument window and return to the Template Parameters tab.
- Add more templates as needed by clicking <new> on the Template Parameters tab.
- To determine the argument order on the Template Parameters tab, use the Move Item Up
and Move Item Down
buttons.
- If there is a primary template that you want to use, select it in the Primary Template list box. This box contains templates for which this class is a specialization. Its parameters to be instantiated appear in the box below the Primary Template list box.
You can define specialization parameters only if you select a template as a primary class. Note: When you try to delete a template that has specialization, the product warns you that the template has references. If you do delete the template, such specialization will generate an error when you check a model.
- Click OK.
The template is listed in the browser in the Classes category.
Results
Once you have created the template class, you can begin using it directly in your code.
You can create templates in other situations. For example, you can:
See also Instantiating a template class.