Download presentation
Presentation is loading. Please wait.
1
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types Require one or more type parameters to specify how to customize a generic class
2
Define template class template class ClassName { public: // constructor void set( T a); T get(); // other functions; private: T x; };
3
Implementation template Before each function definition template ClassName ::ClassName(){} template ClassName ::set( X a) { x = a;} template Y ClassName ::get(){ return x;}
4
Use template – main function When create a object of the template class, specify the data type be used for this object in a angle bracket Declare a variable ClassName x; ClassName y;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.