40 lines
819 B
C++
40 lines
819 B
C++
|
#include <iostream>
|
||
|
|
||
|
class Explicit{
|
||
|
public:
|
||
|
int data;
|
||
|
Explicit();
|
||
|
Explicit(int argument);
|
||
|
Explicit(const Explicit &original);
|
||
|
~Explicit();
|
||
|
};
|
||
|
|
||
|
class Implicit{
|
||
|
public:
|
||
|
int data;
|
||
|
};
|
||
|
|
||
|
Explicit::Explicit() { this->data=0; }
|
||
|
Explicit::Explicit(int a) {this->data=0; }
|
||
|
Explicit::Explicit(const Explicit &orig){this->data = orig.data;}
|
||
|
Explicit::~Explicit(){}
|
||
|
|
||
|
int main(){
|
||
|
Explicit e1; //static ctor call
|
||
|
Explicit *e2;
|
||
|
|
||
|
e2 = new Explicit(); //dynamic ctor call
|
||
|
delete e2; //dynamic dtor call
|
||
|
|
||
|
e2 = new Explicit(2); //dynamic ctor call
|
||
|
Explicit e3 = *e2; //copy ctor
|
||
|
delete e2; //dtor
|
||
|
|
||
|
Implicit i1; //ctor
|
||
|
Implicit *i2 = new Implicit(); //ctor
|
||
|
Implicit i3 = *i2; //implicit copy ctor
|
||
|
delete i2; //dtor
|
||
|
|
||
|
return 0; // dtor e1, e3, i1, i3
|
||
|
}
|