if i declared something like this
int myValue..........
.
.
.
.
will this will call destructor when it goes out of scope?
Thanks
Vishal
Printable View
if i declared something like this
int myValue..........
.
.
.
.
will this will call destructor when it goes out of scope?
Thanks
Vishal
Hi Vishal,
For generic data type object (i.e myvalue), no destructor is called. At least we can control to that level.
For any other user defined data type, the destructor is called when object goes out of scope.
Hope so I understood your question clearly...
Regards
Nagesh
No constructors or destructors are called for this type of value (int, float, char, ...). You have constructors and destructors only for classes and structures.
However, the memory will be freed when the variable goes out of scope. This includes calling the destructor for classes and structures.
just a thought.
Is it possible to have a destructor for the defined types.
If by "defined" types you mean int, long, float, ... AFAIK, I don't think it's possible.
The closest you can do is create a class that will encapsulate just this type and create a constructor and destructor as suit you.
But I hardly see any interest in that ... At least about the destructor, even though the constructor can make sure we have an initialized value ...Code:class MyInt
{
public:
MyInt() {i = 0;}
~MyInt() {i = 0;}
...
int i;
};
Ok thanks for the response..........
just to add..........
i have seen somewhere that we can define value as this also
int i(4)..........
is it correct.....
Thanks
Vishal
Try it and see what your compiler says ;)
Hi Vishal,
You can define in that way also.
It means the same as i=4 (i.e. Calling Integer constructor)
The genaric data type are same as of user defined data type only.
For generic data type Operator Overloading (i.e +, - /) etc is done internally.So you can easily use that. The only difference with generic data type is you do not have access to that level.
Regards
Nagesh