- #1
Dembadon
Gold Member
- 659
- 89
Homework Statement
I am trying to allocate memory on the heap (free-store) for an array of characters using one of my struct members, which is a pointer. However, I am running into scoping issues no matter how I try to go about doing it.
Homework Equations
<data type> *<pointer name>;
<pointer name> = new <data type>[ <size of array> ];
I am using the gcc compiler in unix.
The Attempt at a Solution
Here is my struct:
Code:
struct card {
char *pSuit;
int rank;
char color;
};
Here is a snippet of my initialization section within main:
Code:
pSuit = new char[ 11 ];
Shouldn't this allocate space on the heap for an array of 12 characters? The compiler keeps barking at me, saying: "‘pSuit’ was not declared in this scope". When I try to allocate memory within my struct in hopes to resolve the scoping problem, it tells me the action is forbidden.
Last edited: