DEV Community

Discussion on: C++ Copy Constructors

Collapse
 
tomislavkraljic profile image
Tomislav Kraljic • Edited
    Student* s1 = new Student("Tommy", 23);
    std::cout << s1 << std::endl;

    Student* s2(s1);
    std::cout << s2 << std::endl;
Enter fullscreen mode Exit fullscreen mode

You want to create a new instance of Student with a pointer. The pointer points to a memory address when you create the first object. When you shallow copy it, it also copies the memory address of the first student.