Why don't you want to dynamically create the object?Quote:
ya I want manage life time of Object myself with out creating dynamically
Why don't you want to dynamically create the object?Quote:
ya I want manage life time of Object myself with out creating dynamically
You cannot deallocate an object that you did not allocate. For non heap objects, the compiler manages the objects lifetime and reclaims the memory. Under java you do not control the objects lifetime even when allocated dynamically, the GC determines when to actually destroy the object when no references to it remain.Quote:
Originally posted by ccbalamurali
ya I want manage life time of Object myself with out creating dynamically (using New oprator) like Java? I think there ways to do this? I do't know exactly.
regs
Balamurali C
You can add a Destroy() method to the object and use that to clean up all the resources that the object has allocated (memory, handles etc.) but you cannot free the memory that the object occupies.
Why do you want to delete the object?
What is the problem you are trying to solve?
You can manage the lifetime of object even on stack try somthing like...Quote:
Originally posted by ccbalamurali
ya I want manage life time of Object myself with out creating dynamically (using New oprator) like Java? I think there ways to do this? I do't know exactly.
regs
Balamurali C
Hope this helps,Code:int main()
{
// myObj doesnt exits....
{
CMyClass myObj;
// Do something with myObj
}
// myObj doesnt exits....
}
Regards,
Usman.
ya this is the one of the interview question? so I want know the Solution
Regards
Balamurali c
I agree with usman. Putting the code in the block really helps.
:D