pTeamMember
isn't a pointer. It's an array of pointers-to-CCharacter
.
In your second example, you're assigning to one of the pointers in the array. You could do the same with pTeamMember
:
pTeams[team]->pTeamMember[i] = 0;
Question
I want to make a pointer to an instance of a class. Many instances - that is why I made an array which saves all of those. But how can I set the value of a pointer in a class to 0? That is the code... Maybe you know what I'm talking about
public:
CCharacter *pTeamMember[15];
And in another file:
pTeams[team]->pTeamMember = 0;
It causes following error.
error C2440: '=' can't convert 'int' into 'CCharacter *[15]
What I don't understand is, that this don't causes any errors:
public:
Team *pTeams[31];
And in another file:
pTeams[i] = 0;
Does anyone have ideas?
Solution
pTeamMember
isn't a pointer. It's an array of pointers-to-CCharacter
.
In your second example, you're assigning to one of the pointers in the array. You could do the same with pTeamMember
:
pTeams[team]->pTeamMember[i] = 0;
OTHER TIPS
To set the value of a pointer to 0 (presuming you mean point at nothing), you can do the following. Note that you can use 0 or nullptr (which is valid as of C++ 11)
int *p = nullptr;
In regards to your specific example, change
pTeams[team]->pTeamMember=0;
to
pTeams[team]->pTeamMember[index]=0;