Professional Documents
Culture Documents
Templates Polymorphism
Templates Polymorphism
OUTPUT
Value of a is 5
Output
Operator overloading
Like + performs addition of two integers , also strings same way an operator is
made to work totally different when used with objects of time class.
Dynamic binding(Late binding)
Virtual Function
#include<iostream> sample()
Using namespace std; { a=10;}
Class Sample void disp(int a)
{ int a; { cout<<”The value of argument a =”<<a;
Public: cout<<”\n The value of data member
a=”<<this->a; }};
Int main()
{ sample s;
s.disp(20);
return 0; }
Output :
The value of argument of a = 20
The value of data member a = 10
5. Explain virtual function with example.
Output :
Base class pointer assign address of base class object
Simple function in base class
Virtual function of base class
Base class pointer assign address of derived class object
Simple function in base class
Same name with virtual function of base class in derived class.
7. Explain pure virtual functions
Syntax
Virtual void display()=o OR virtual void display(){}
TEMPLATES
1. Explain function and class templates with appropriate example.
Example:
Class Template :
2. Exceptional handling. Explain how to handle an exception with
appropriate example.
In programming two most common types of error are logical error and
syntax error.
The syntax error is detected during compilation of program , logical error
will detect during execution of program. So it is difficultto handle logical
error.
Exceptional handling provides mechanism for handling logical errors.
Steps:
When the value of b is zero at that time exception will throw and this exception will catch in
catch block and print the message value is zero.
Write notes on STL.
Components of STL
There are 3 components of STL as follows
Container
Algorithm
Iterator