Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.

Similar presentations


Presentation on theme: "Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types."— Presentation transcript:

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;


Download ppt "Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types."

Similar presentations


Ads by Google