When do you call copy constructors?
Copy constructors are called in these situations:
i.)when compiler generates a temporary object
ii.)when a function returns an object of that class by value
iii.)when the object of that class is passed by value as an argument to a function
iv.)when you construct an object based on another object of the same class
i.)when compiler generates a temporary object
ii.)when a function returns an object of that class by value
iii.)when the object of that class is passed by value as an argument to a function
iv.)when you construct an object based on another object of the same class
Name the implicit member functions of a class.
i.) default ctor
ii.) copy ctor
iii.) assignment operator
iv.) default destructor
v.) address operator
ii.) copy ctor
iii.) assignment operator
iv.) default destructor
v.) address operator
Explain storage qualifiers in C++.
i.) Const - This variable means that if the memory is initialised once, it should not be altered by a program.
ii.) Volatile - This variable means that the value in the memory location can be altered even though nothing in the program code modifies the contents.
iii.) Mutable - This variable means that a particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
ii.) Volatile - This variable means that the value in the memory location can be altered even though nothing in the program code modifies the contents.
iii.) Mutable - This variable means that a particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
Explain dangling pointer.
When the address of an object is used after its lifetime is over, dangling pointer comes into existence. Some examples of such situations are: Returning the addresses of the automatic variables from a function or using the address of the memory block after it is freed.
In what situations do you have to use initialization list rather than assignment in constructors.
When you want to use non-static const data members and reference data members you should use initialization list to initialize them.
When does a class need a virtual destructor?
If your class has at least one virtual function, you should have a virtual destructor. This allows you to delete a dynamic object through a baller to a base class object. In absence of this, the wrong destructor will be invoked during deletion of the dynamic object.
What is the type of “this” pointer? When does it get created?
It is a constant pointer type. It gets created when a non-static member function of a class is called.
Explain Stack unwinding
Stack unwinding is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.
No comments:
Post a Comment