I’m working on a project for school, and faced this elementary problem (it’s not part of the assignment, merely a set-back in the initial stage of the problem).
I am trying to create a pointer that points to an array. The array contains pointers, each of which points to a class object “Customer”.
Here is customer.h.
Here is customer.cpp.
Finally, here is my main, which is causing problems:
#include "customer.h"
int main () {
Customer** c_array;
c_array = new Customer*[10];
cout << c_array[0]->getEnter() << endl;
return 0;
}
Any ideas?
Here’s the error:
Segmentation fault: 11
Allocating an array of pointers does not allocate anything for what those pointers point to. So your statement:
creates an array of pointers, but they point somewhere random (causing a segmentation fault when you try to dereference them). You will need to write a loop to initialise those pointers also.