So I've made a working blackjack program but I'm trying to implement new things as I'm learning them. I'm still fairly new to C++ (and programming in general as well). I'm trying to make a class that makes a deck of cards. I don't know if doing something different would be better. And I'll bet the way I did it is not the best. But anyway I'm getting this weird compile error which I thought I might have fixed but I would up getting a different one. So heres my code now. (Sorry so sloppy)
As for the stuff in main i just wanted to test it.
And before I got this (read some post about declaring inside the class definition.
1 2 3 4 5 6 7 8 9 10 11
class Deck
{
public:
struct DeckStructure
{
string letter;
int value;
}DeckStructure[52];
Deck();
~Deck();
};
And it says in the same two places : invalid use of non-static date member Deck::DeckStructure.
Also I know I need to convert the int to a string in the last part of the constructor. (Is there an easy way to that?) If I could get this to work then I'll move on to that.
I know I'm doing something wrong. Any and all help is greatly appreciated. Thanks
If you define a variable inside the constructor or any function in general then it is local in the function.
So, if you define the object from your DeckStructure in the constructor then when the constructor is done, your object is automatically deleted. So you have to do it the way you have at your second code.
Also when you call the members of a class you have to use the dot notation, like you do for the struct.
[edit] Sorry, i just saw yur last question. I used DeckStructure[q].letter = static_cast<char> (static_cast<int> ('0') + (temp) );
It casts the char '0' to int, then it adds to it the temp value and finally casts it to char.
Yes, '::' is to define members of a class, not to access them. You have to use '.' to access them or '->' if you use a pointer.
Also i don't think that it is a good technique to use the same name for the class name and the class object. It makes it difficult for somebody to understand it. Atleast for me that i'm still learning...
I know about the same name thing lol , I wound up confusing my self a lot. It was just for simplicity(at the time) to try to make it work. Sorry 'bout that.