Code:
int main()
{
balance* p;
char s[80];
double n;
int i;
try {
p = new balance[3]; //allocate entire array
} catch (bad_alloc xa){
cout << "Allocation failure..." << endl;
return 1;
}
//note use of dot, not arrow operaors
p[0].set(12387.87, "Ralph Wilson");
p[1].set(144.00, "A. C. Conners");
p[2].set(-7.87, "I. M. Broke");
for(i=0; i < 3; i++){
p[i].get_balance(n,s);
cout << s << "'s balance is: " << n << endl;
}
delete [] p;
return 0;
}
I am confused about p[0].set(...). If p is a pointer to an array, how come -> gives compilation error. Can any one please clarify me?
I'll lock the thread because OP requested a delete, but I restored the original question because it had already been answered by the time OP deleted it.
Markbnj
Last edited by a moderator: