🗊Презентация C++ templates

Нажмите для полного просмотра!
C++ templates, слайд №1C++ templates, слайд №2C++ templates, слайд №3C++ templates, слайд №4C++ templates, слайд №5C++ templates, слайд №6C++ templates, слайд №7C++ templates, слайд №8C++ templates, слайд №9C++ templates, слайд №10C++ templates, слайд №11C++ templates, слайд №12C++ templates, слайд №13C++ templates, слайд №14C++ templates, слайд №15

Вы можете ознакомиться и скачать презентацию на тему C++ templates. Доклад-сообщение содержит 15 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





Chapter 22 - C++ Templates
Описание слайда:
Chapter 22 - C++ Templates

Слайд 2





22.1	Introduction
Templates 
Easily create a large range of related functions or classes
Function template - the blueprint of the related functions
Template function - a specific function made from a function template
Описание слайда:
22.1 Introduction Templates Easily create a large range of related functions or classes Function template - the blueprint of the related functions Template function - a specific function made from a function template

Слайд 3





22.2	Class Templates
Class templates 
Allow type-specific versions of generic classes
Format:
	template <class T>
	class ClassName{
definition
}
Need not use "T", any identifier will work
To create an object of the class, type
ClassName< type > myObject;
Example: Stack< double > doubleStack;
Описание слайда:
22.2 Class Templates Class templates Allow type-specific versions of generic classes Format: template <class T> class ClassName{ definition } Need not use "T", any identifier will work To create an object of the class, type ClassName< type > myObject; Example: Stack< double > doubleStack;

Слайд 4





22.2	Class Templates (II)	
Template class functions
Declared normally, but preceded by template<class T>
Generic data in class listed as type T
Binary scope resolution operator used
Template class function definition:
template<class T>
MyClass< T >::MyClass(int size)
{	
   myArray = new T[size];
}
Constructor definition - creates an array of type T
Описание слайда:
22.2 Class Templates (II) Template class functions Declared normally, but preceded by template<class T> Generic data in class listed as type T Binary scope resolution operator used Template class function definition: template<class T> MyClass< T >::MyClass(int size) { myArray = new T[size]; } Constructor definition - creates an array of type T

Слайд 5







1. Class template definition

1.1 Function definitions

1.2 Stack constructor
Описание слайда:
1. Class template definition 1.1 Function definitions 1.2 Stack constructor

Слайд 6







1.3 push
1.4 pop
Описание слайда:
1.3 push 1.4 pop

Слайд 7







1. Load header

1.1 Initialize doubleStack

1.2 Initialize variables

2. Function calls
Описание слайда:
1. Load header 1.1 Initialize doubleStack 1.2 Initialize variables 2. Function calls

Слайд 8







2. Function calls

3. Output
Описание слайда:
2. Function calls 3. Output

Слайд 9







Program Output
Описание слайда:
Program Output

Слайд 10





22.3	Class Templates and Non-type Parameters
Can use non-type parameters in templates
Default argument
Treated as const
Example:
template< class T, int elements > 
Stack< double, 100 > mostRecentSalesFigures; 
Declares object of type Stack< double, 100>
This may appear in the class definition:
T stackHolder[ elements ]; //array to hold stack 
Creates array at compile time, rather than dynamic allocation at execution time
Описание слайда:
22.3 Class Templates and Non-type Parameters Can use non-type parameters in templates Default argument Treated as const Example: template< class T, int elements > Stack< double, 100 > mostRecentSalesFigures; Declares object of type Stack< double, 100> This may appear in the class definition: T stackHolder[ elements ]; //array to hold stack Creates array at compile time, rather than dynamic allocation at execution time

Слайд 11





22.3	Class Templates and Non-type Parameters (II)
Classes can be overridden  
For template class Array, define a class named
Array<myCreatedType>
This new class overrides then class template for myCreatedType
The template remains for unoverriden types
Описание слайда:
22.3 Class Templates and Non-type Parameters (II) Classes can be overridden For template class Array, define a class named Array<myCreatedType> This new class overrides then class template for myCreatedType The template remains for unoverriden types

Слайд 12





22.4	Templates and Inheritance
A class template can be derived from a template class
A class template can be derived from a non-template class
A template class can be derived from a class template
A non-template class can be derived from a class template
Описание слайда:
22.4 Templates and Inheritance A class template can be derived from a template class A class template can be derived from a non-template class A template class can be derived from a class template A non-template class can be derived from a class template

Слайд 13





22.5	Templates and friends
Friendships allowed between a class template and 
Global function 
Member function of another class
Entire class
friend functions 
Inside definition of class template X:
friend void f1(); 
f1() a friend of all template classes
friend void f2( X< T > & );
f2( X< int > & ) is a friend of X< int > only.  The same applies for float, double, etc.
friend void A::f3(); 
Member function f3 of class A is a friend of all template classes
Описание слайда:
22.5 Templates and friends Friendships allowed between a class template and Global function Member function of another class Entire class friend functions Inside definition of class template X: friend void f1(); f1() a friend of all template classes friend void f2( X< T > & ); f2( X< int > & ) is a friend of X< int > only. The same applies for float, double, etc. friend void A::f3(); Member function f3 of class A is a friend of all template classes

Слайд 14





22.5	Templates and friends (II)
friend void C< T >::f4( X< T > & );
C<float>::f4( X< float> & ) is a friend of class X<float> only

friend classes
friend class Y;  
Every member function of Y a friend with every template class made from X
friend class Z<T>;  
Class Z<float> a friend of class X<float>, etc.
Описание слайда:
22.5 Templates and friends (II) friend void C< T >::f4( X< T > & ); C<float>::f4( X< float> & ) is a friend of class X<float> only friend classes friend class Y; Every member function of Y a friend with every template class made from X friend class Z<T>; Class Z<float> a friend of class X<float>, etc.

Слайд 15





22.6	Templates and static Members 
Non-template class 
static data members shared between all objects
Template classes
Each class (int, float, etc.) has its own copy of static data members
static variables initialized at file scope
Each template class gets its own copy of static member functions
Описание слайда:
22.6 Templates and static Members Non-template class static data members shared between all objects Template classes Each class (int, float, etc.) has its own copy of static data members static variables initialized at file scope Each template class gets its own copy of static member functions



Теги C++ templates
Похожие презентации
Mypresentation.ru
Загрузить презентацию