Computer Science 1037A/B Lecture 38: Templates

30 views4 pages

Document Summary

A c++ template class is a blueprint/prototype for a family of classes. The template class defines a dynarray of elements once, in a general way. Programs using dynarrays can then instantiate separate dynarray classes for as many specific types of elements as necessary. When dynarray object is instantiated, the type of elements it stores must be specified. If specialized dynarray class for that specific type of elements does not already exist, the class is instantiated at compile time from a template. Then, dynarray object of that class can be created by compiler. Template class is declared in a . h file. Occurrences of dynarrayitems :: are replaced by dynarray :: Code for each member function is preceded by template Dynarray objects now have to be declared as. Classes dynarray and dynarray are instantiated from the same template using different template parameter item (int and char)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions