Yes I know it, but, seeing the fact that C++ does not have a "string" type, I prefer to use directly arrays. |
Methods. Not member functions.
So.. I generally handle my class declaration (where i declare all of the member functions and data members) in the header file, and then define the functions in the cpp file. This has a side effect of displaying for whoever happens to be reading the header file to see what functions they have available to them, all of the functions including the private functions and data members that they need not be concerned with. |
There are technical reasons for doing it this way to. Otherwise you end up with cyclic-dependencies and declarations. IDE's handle it better for code finding etc.
Also, I have been in the habbit of putting one class per header file and cpp file combination. (I havn't had much practice before with seperating code into multiple files. prior to devc++, i would have to make the make file to link it all together and I was never good at that.) |
Ideally, Keep the declaration in a single header, and the code in a single cpp file. Not split across files.
It makes sense to me to use a seperate header and cpp file per class. However, lets use the blackjack example since it's a recent topic. If i have a class to represent a card, which is very small: |
Ahhh now it gets interesting. Now I am speaking from my POV.
In this situation, my object of card would be a struct, not a class. While handled almost the same by C++, there is a design difference.
Classes are more complete objects that have a much greater purpose, they have methods.
Structs are simple data structures that hide small amounts of information in an organise fashion.
e.g
1 2 3 4
|
struct card {
int Value;
int Face;
};
|
That would be sufficient enough. I typically don't encapsulate structs as I treat them like a complex-datatype. Now, because it's a struct (really a new data-type) and not a class with an implementation you can declare this in ur Deck header file.
Note: I do know how Structs/Classes are handled by the compiler and language etc. But this is from a design point of view.
Another note: Using private instead of protected, should only be done when there is NO possibility that member or method will need to be inherited.