class Student
{
private:
string name;
int id;
int *test;
int num;
void makeArray();
public:
Student();
Student(int n);
Student(string nm, int i, int n);
void setName(string nm);
void setID(int i);
void setScore(int i, int s);
string getName() const;
int getID() const;
void showScore();
void display();
~Student();
};
Constructor:
1 2 3 4 5 6 7 8 9
void Student::makeArray()
{
int size = Student::num;
int *studentArray;
studentArray = newint[num];
Student::test = studentArray;
test = 0;
}
I have spent the last few hours getting it down to the error in my code being something to do with the constructor. The constructor should dynamically allocate an int array with num elements, assigns the address of the array to
test, and assigns 0 to all the elements.
test = 0; does not assign 0 to all elements. It assigns 0 to test, effectively whiping out the address of the array that was put in there. You need to use a for loop. Something like this:
I figured it out, thanks for the help guys it had to do with the ACTUAL contructor, thought makeArray was the constructor but i needed to call makeArray in the constructor.