Probably because there's about a dozen different meanings to the keyword... stating from memory:Zacariaz wrote:i never really understod the use of "static"...
- A static function will be visible only in its current translation unit (equivalent to the C++ anonymous namespace);
- A static member function will be local to the class, not to individual instances (i.e., you can call it as Class::function() without having a Class object at hand, and it can access only static members);
- A static data member will also be local to the class, not to individual instances (i.e., your Value / Set arrays would be stored once with the class, not individually for each instance, which is what you want);
- A static variable inside a function will be initialized on first call to the function only, and retain its value across subsequent calls to the function.
Note the placement in my first code example; they are class variables, not local to the constructor....and originally i didnt think they would be visible outside the constructor, but i got the impression from your code that they would.
Oops... I just realized my first code example does not compile correctly. You initialize them like this:So, how to initilize them the smart way outside the constructor?
I mean i can declare a variable, but not initialize it outside the constructor, as far as i know.
Code: Select all
class Foo {
static char const bar[];
};
char const Foo::bar[] = "ABCDEF...";
No you don't. The larger your project, the mroe important it is to make your coding follow the abstraction, not the other way round. Trust me on this.but i still need access to card_t::V and card_t::S from deck...
Correct.So, the alternative is to make functions in card_t for just about everything and only let deck be handling the order of the cards, and not having anything to do with what they actually contain. (this would probably be the right way to go however)
Since you are taking all this in exceptionally good grace, it is actually fun to help you with this. You're very welcome.I have never done much OOP programming so excuse me if im asking some stupid questions. I have allready learned alot and i hope to learn alot more.