#include <iostream>
using namespace std;
class Students {
private:
int size; // number of students
public:
Students() {
this->size = 0;
}
Students(const Students &other) {
this->size = other.getSize();
}
void setSize(int size) {
this->size = size;
}
int getSize() const {
return this->size;
}
};
int main() {
// Create object using default constructor
Students students1;
students1.setSize(10);
cout << "Students 1 has size " << students1.getSize() << endl;
// Create object using copy constructor
Students students2 = students1;
students2.setSize(20);
cout << "Students 2 has size " << students2.getSize() << endl;
}
Comments
Leave a comment