"Card" is not a type

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
Last edited on
C++ does not allow to declare arrays of references. So this declaration

void Deal(Card& deck[]);

is invalid.
Last edited on
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.
Thanks for the info. However even if I remove it it tells me Card is not a type.
Does anybody know what I'm doing wrong?



Regarding the array, If I passed it in without the brackets [], could I still access deck[i]?
Show your updated code.
[] 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.
Last edited on
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
Last edited on
Again: http://cplusplus.com/forum/beginner/73857/#msg394839

Also, it means for whatever reason Card is not defined in that scope. Check my above list of common errors I've had in the past.
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!
Last edited on
Topic archived. No new replies allowed.