Constructor Types
C++ supports default, parameterized, copy, and move constructors. Initializer lists are the preferred way to initialize members.
Example
class Student {
private:
string name;
int grade;
vector<int> scores;
public:
// Default constructor
Student() : name("Unknown"), grade(0) {}
// Parameterized constructor with initializer list
Student(string n, int g) : name(n), grade(g) {}
// Copy constructor
Student(const Student& other)
: name(other.name), grade(other.grade), scores(other.scores) {}
// Destructor
~Student() {
cout << name << " destroyed" << endl;
}
};
Student s1("Alice", 10);
Student s2 = s1; // copy constructor called 