C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - General Questions (Q.No. 5)
5.
For automatic objects, constructors and destructors are called each time the objects
Discussion:
24 comments Page 1 of 3.
Neha said:
9 years ago
It is said in Stroustrup
"An object constructed by explicit or implicit use of a constructor is automatic and will be destroyed at the first opportunity.".
So if I define a new object of any class using a new function.
Will it still be considered automatic and be deleted ?
or would it be saved in the heap such that it will be deleted only using delete
command ?
className objName = new(className); //this is what I have in mind.
"An object constructed by explicit or implicit use of a constructor is automatic and will be destroyed at the first opportunity.".
So if I define a new object of any class using a new function.
Will it still be considered automatic and be deleted ?
or would it be saved in the heap such that it will be deleted only using delete
command ?
className objName = new(className); //this is what I have in mind.
Vikrant said:
9 years ago
Constructor Special type of member function whose name same as class name constructor are automatically called when object is created and Enter in leave in scope.
Destructor are automatically called when object is Destroyed.
Destructor are automatically called when object is Destroyed.
Shyam biradar said:
6 years ago
Automatic objects means local variables which are created in stackframe.
So now, you visualize what happens to local variables when a stack frame is created and when its destroyed.
So now, you visualize what happens to local variables when a stack frame is created and when its destroyed.
Jackode said:
9 years ago
I guess something like:
void function (){
class {...} a;
// use a here
}
a is automatic object that constructed and destructed in scope of function.
void function (){
class {...} a;
// use a here
}
a is automatic object that constructed and destructed in scope of function.
Sagar said:
3 months ago
When object is created the constructor is called automatically, and when we deal with the local variables they are created in the stack.
Lilly said:
9 years ago
What is the mean of automatic object? then I feel it should create automatically at runtime according to the method. Thats write?
Viknesh said:
9 years ago
An automatic object is not a dummy argument. An automatic object always has the controlled automatic storage class.
Ganesh said:
9 years ago
That is correct automatic object means Constructor can not need to called by using object.
Bhargavi said:
10 years ago
What is automatic object?
Normally we create classes then only object is created.
Normally we create classes then only object is created.
Vikrant said:
9 years ago
Automatic object means Constructor can not need to called by using object.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers