Section 4 : Constructors and Destructors, Dynamic memory management Flashcards
(7 cards)
What is a constructor in C++?
A special function with the same name as the class, called automatically when an object is created. It has no return type.
What is a default constructor?
A constructor with no parameters. Automatically created by C++ if no constructor is defined.
What is constructor overloading?
Having multiple constructors in the same class, each with different parameter lists.
What is a copy constructor?
A constructor that creates a new object as a copy of an existing object. It takes a reference to another object of the same class.
What is a destructor?
A special function that is automatically called when an object is destroyed. It starts with ~ and has no parameters or return type.
What is the purpose of the :: scope resolution operator in C++?
The :: operator is used to access a variable or function from a specific scope, such as a class, namespace, or the global scope.
class MyClass {
public:
void show();
};
void MyClass::show() {
// Defined outside the class
}