Customer *Customers[10]; You create an array of pointers to that object.
Why don't you do:
Customer Customers[10];
Customer[numberOfCustomers] = createCustomer();
-------------1.Basically you are misuing pointers. In C and C++, when a variable is uninitialized, it contains a garbage value. Thus, Customers from 0 to 9 point to garbage values. They are pointers, which means they point in unknown places in the memory.
Then, you are assigning a value to that unknown memory location. This is the error. Before assigning, you have to be sure that the pointer points to a valid memory location of that object.
This is what you are doing.
int main()
{
int *p, x;
x = 10;
*p = x;
}
This is what youshould be doing.
int main()
{
int *p, x;
x = 10;
p = &x;
}
If you still want an array of pointers to Customer objects, you should write:
Customers[numberOfCustomers] = &(createCustomer()); //the address of the object
2.
Don't use void main(void). Just int main(). The use of void in the parentheses is redundant. It is required in C but not in C++.