I am trying to reference a Card struct in a function, but it is telling me it doesn't exist. Could somebody please help me with what the issue is? I declared Card before I declared the deal function
struct Card
{
int something;
};
class Player
{
public:
void Deal(Card& deck[]);
};
void Player::Deal(Card& deck[]) //error: Card is not a type
{
}
int main()
{
Card deck[52];
Player player;
Player.Deal(deck);
return 0;
}
Excuse any simple mistakes I may have made in the syntax, I just wrote this straight off my head since my actual code is too big. The main issue is the fact that Player::Deal doesn't recognise Card
Is Card in a namespace and you forgot to quantify it? Is Card in another file and accidentally hidden by a preprocessor directive? Is Card visible in the method definition's scope.
What you have above should compile. Try compiling it to see if it does. It might help you find your error.
[] is a pointer offset and dereference all in one.
1 2 3 4
void *a;
...
a[5] //is the same as
*(a + 5);
So in short, you would need to replace [] with *, but better would be to make a class Deck or Hand to handle the Card collection abstractly. That way you don't need to pass around pointers.
Okay well I just checked and what I did type did actually compile... But I don't see the difference between my example and my actual code
Does anybody know what "'Card' is not a type" error actually refers to?
I can't exactly up my actual code because it is unsplit, massive in general and probably would make a few of you guys cry with how noob I am... but I thought the error would come if I had not declared Card, when I actually have
I'm not sure whether to be happy or sad that it is something to do with my original code
After ages of searching I think I found the error. I had previously declared Player as a child of card even though it wasn't even necessary, just a shortcut that the book I was studying did. All I had to do to fix it was unparent it. Turns out that was causing the problem. Damn shortcuts
Thanks everyone for your help I got a lot of new info out of this, so hope I didn't waste your time :P
And double thanks to Mathhead200 for telling me to use pointer, saved me another 30 minutes of frustration!