I'm busy with writing a piece of code. The function of the code is the following: I have a class Student. I want to copy the grade from freshman to freshman2. Then I delete freshman, but freshman2 should still hold the grade from freshman. I want/need to do this with a copy constructor. I'm not that familiar with a copy constructor, however. This is what I have uptil now. Can someone please help me with this?
#include <iostream>
using namespace std;
class Student
{
public:
int *grades;
int size;
Student (unsigned int n) {grades = new int[n]; size = n;}
Student(const int& other);
~Student() {delete[] grades;}
Student(Student &old_student) {}
};
int main()
{
Student *freshman = new Student(1);
freshman -> grades[0] = 8;
Student *freshman2 = new Student(*freshman);
delete freshman;
cout << freshman2 -> grades[0] << endl;
}
Thanks in advance guys:)