copy constructor problem

int main() {
Student *s1, *s2;
s1 = new Student (3);
s2 = new Student (*s1);
s1->print(); // 0 0 0
s2->print(); // 0 0 0
s1->setMark (0, 70);
s1->setMark (1, 80);
s1->setMark (2, 90);
s1->print(); // 70 80 90
s2->print(); // 70 80 90
delete s1;
} delete s2;

if we did not initialize a copy constructor for the program,the program will set a copy constructor which parameter pass by reference,pass by reference parameter we can substitude pointer inside?why?can anyone explain?
s2 = new Student (*s1);
Here, you are trying to call the constructor

Student::Student(Student);

You haven't "substituted a pointer inside".

why cant i put student(s1)?
Because s1 is a pointer (Student*) but the copy constructor expects a reference (const Student&).
Last edited on
Topic archived. No new replies allowed.