#include<iostream>
#include<ctime>
#include<boost/progress.hpp>
usingnamespace std;
class parent
{
public:
virtualvoid dynamic_display(){
cout<<"It is implemented in Parent class\n";
}
};
class child:public parent
{
staticint static_count;
staticint dynamic_count;
public:
void static_display(){
int temp,i;
for (i=0;i<100000;i++)
temp=temp+i;
cout<<"Static Function is called"<< static_count<<"times\n";
static_count=static_count+1;
}
void dynamic_display(){
int temp,i;
for (i=0;i<100000;i++)
temp=temp+i;
cout<<"Dynamic function is called"<<dynamic_count<<"times\n";
dynamic_count=dynamic_count+1;
}
};
int child::static_count=1;
int child::dynamic_count=1;
int main(){
clock_t t1;
clock_t t2;
child chld;
//first call to static method
t1=clock();
cout<< "Calculating....";
chld.static_display();
t2=clock()-t1;
cout<<"The number of processor clicks is" <<t2<<"time is"<<((float)t2/CLOCKS_PER_SEC)<<"\n";
//First call to dynamic method
t1=clock();
cout<< "Calculating....";
chld.dynamic_display();
t2=clock()-t1;
cout<<"The number of processor clicks is" <<t2<<"time is"<<((float)t2/CLOCKS_PER_SEC)<<"\n";
//second call to static method
chld.static_display();
//second call to dynamic method
chld.dynamic_display();
//third call to static method
chld.static_display();
//third call to dynamic method
chld.dynamic_display();
return 0;
}
I am getting the following as output
Calculating....Static Function is called1times
The number of processor clicks is0time is0
Calculating....Dynamic function is called1times
The number of processor clicks is0time is0
Static Function is called2times
Dynamic function is called2times
Static Function is called3times
Dynamic function is called3times
i am actually trying to calculate the time to execute a statically binding method and a dynamically binded one.consider only the first four lines in my output.Why am i not getting the actual result.where have i gone wrong please advice.............
would the way we create object's i.e in stack or heap, affect the way in which the methods are binnded (statically or dynamically) guestgulkan..........