P
Pranav
Can any one help me about how many times the Ctor and Dtor are getting
called in the following code? I am getting o/p but not getting it..,
Re cnt value___
class MyClass{
public :
static int cnt;
MyClass ( );
void disp( );
~MyClass( );
};
MyClass :: MyClass( ){
cnt++ ;
cout << "Ctor " << cnt << "___" ;
}
MyClass :: ~MyClass( ){
cnt-- ;
cout << "Dtor " << cnt << "___" ;
}
void MyClass :: disp( ){
cout << "\nDisplay Function " << cnt << endl;
}
int MyClass :: cnt = 0;
main()
{
stack< MyClass, vector<MyClass> > myStack;
int i;
for ( i=0; i<10; i++ )
myStack.push( MyClass() );
for ( i=0; i<5; i++ ) {
myStack.top.disp();
myStack.top.pop();
}
//Code Ends Here_____________
char asdf;
cin >> asdf;
return 0;
}
called in the following code? I am getting o/p but not getting it..,
Re cnt value___
class MyClass{
public :
static int cnt;
MyClass ( );
void disp( );
~MyClass( );
};
MyClass :: MyClass( ){
cnt++ ;
cout << "Ctor " << cnt << "___" ;
}
MyClass :: ~MyClass( ){
cnt-- ;
cout << "Dtor " << cnt << "___" ;
}
void MyClass :: disp( ){
cout << "\nDisplay Function " << cnt << endl;
}
int MyClass :: cnt = 0;
main()
{
stack< MyClass, vector<MyClass> > myStack;
int i;
for ( i=0; i<10; i++ )
myStack.push( MyClass() );
for ( i=0; i<5; i++ ) {
myStack.top.disp();
myStack.top.pop();
}
//Code Ends Here_____________
char asdf;
cin >> asdf;
return 0;
}