0% found this document useful (0 votes)
12 views

Introduction To Programming - CS201 Power Point Slides Lecture 42

These slides are to introduce programming for bignners

Uploaded by

Hasnain ullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Introduction To Programming - CS201 Power Point Slides Lecture 42

These slides are to introduce programming for bignners

Uploaded by

Hasnain ullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

Introduction to

Programming
Lecture 42
template <class
T>
Templat
e
Classes
Stac
k
Last In
First
Out
template <class
T>
class ClassName
{
definition
}
Member function
template <class T>
Class_Name <T> :: Function_Name (Argumen
{
// body of function
}
Class_Name :: Function_Name ( Argument
Argumen
{
// body of function
}
Example
template <class T>
class Number
{
private :
T MyNumber ;
public:
Number ( T n ) ;
display ( ) ;
}
Example

Number <int> x ;
Number <double> y
Non Type
Parameter
s
template <class T , int
elements>
int x
[ 100 ] ;
Static
Member
Variables
Number <int> x
;
Example
class PhoneCall
{
private :
int lengthOfCall ;
char billCode ;
public :
PhoneCall ( const int i , char b ) ;
PhoneCall ( PoneCall & p ) ;
PhoneCall PhoneCall :: operator - ( void
void display ( void ) ;
};
Example
PhoneCall PhoneCall :: operator -( vo
v
)
{
PhoneCall temp ( * this ) ;
temp.billCode = 'C' ;
return ( temp ) ;
}
Friend
Function
a+
‘a’ is a 2 is an
object of a integer value
class

2;
a+2;
should be
same as
2+a;
friend f
();
friend f ( x <T> & )
friend f ( X <int>
&);
friend class Y
;
friend A :: f ( )
;
friend A :: f ( X< T > &
Example
template <class T>
class Stack
{
private :
int size ;
T array [ ] ;
public :
Stack ( ) ;
void push ( T ) ;
T pop ( ) ;
bool isEmpty ( ) ;
bool isFull ( ) ;
// Etc.
};
Example

Stack <int> x ;
Stack <double> x ;
Last In
First
Out
Queue
Link
List
First In
First
STL
Standard
Template
Library

You might also like