Magic!!!
Google developers' page asks you to enchant the users.
So get ready for some magic.
You know that anything created will be destroyed. And the corollary is, anything destroyed would have been created earlier. Law of conservation of mass - Is it?
P.S. It is not the law of conservation of mass. The law says mass can not be created or destroyed. In my excitement to write a blog about magic, I overlooked it.
So in C++, creation is assisted (or followed) by constructor and destruction by destructor. So if I show you a program in which there is a destructor without a constructor, we are defying the common principle.
Take down this code and execute it.
So get ready for some magic.
You know that anything created will be destroyed. And the corollary is, anything destroyed would have been created earlier. Law of conservation of mass - Is it?
P.S. It is not the law of conservation of mass. The law says mass can not be created or destroyed. In my excitement to write a blog about magic, I overlooked it.
So in C++, creation is assisted (or followed) by constructor and destruction by destructor. So if I show you a program in which there is a destructor without a constructor, we are defying the common principle.
Take down this code and execute it.
#include<iostream>
using namespace std;
class A
{
public:
A(){cout<<"constructor ";}
~A(){cout<<"destructor ";}
};
void fn1(A obj)
{
cout<<"hello magical world ";
}
int main()
{
A obj1;
fn1(obj1);
}
What did you say the output was. Is it
constructor hello magical world destructor
?
No, It is not? Then is it
constructor hello magical world destructor destructor
?
It is. Isn't it? So the question is, where is the extra destructor coming from? One object - one constructor, one destructor. That is what is expected. But here we have one constructor and two destructors!
So we have destroyed an object without constructing it? Is this the THE MAGICAL OBJECT?
Tell me the reason.
Comments
Post a Comment