Hi,
I haven't looked at your code, but there are some things I can comment on based on other replies, and on what you have said.
When adding members, add a suffix (m_) before their names (Unless they are totally obvious). Members that are marked "private" can have different suffix so that to help programmers search for public-type members much easier. |
Here is a concept for you: All the class data members should be
private:
. Your code snippet had two private sections, because class members are private by default, unless marked otherwise. Personally, I think it is overkill to mark private members with
p_
in the variable name. There are some that recommend against having
for member variables.
With globals, consider that it should be possible to write all of your code with
no globals at all. I am not saying that globals should be banned outright - there are valid situations for
experienced coders to use them, but beginners really should avoid them. And the actual advice is the opposite of globals: keep the scope of your variables as tight as possible.
Another thing is that one should put their own code into it's own
namespace
.
With magic numbers, make them a
const
variable instead, and use that variable name in the code:
1 2 3 4
|
// constexpr is more strict than const, it's constness cannot be cast away
constexpr std::size_t DaysInWeek = 7;
std::array<double, DaysInWeek> WeeklyData = {1.0, 21.0, 2.3, 4.7, 6.3, 7.8, 9.2};
| |
For data where you are unsure of how many items there may be, then use a
std::vector
, and not worry about the size of it at all.
In terms of transitioning from C to C++, I acknowledge that it can be a steep learning curve, but realise that it is a different paradigm. That is, it it is a completely different mind set. With C++, make use of the STL with it's containers and algorithms etcetera to do work for you. If you have copied or learnt from a site that has C code, then try to find a site that has actual C++ code. The other thing is to try and get a good grounding in actual C++ code before trying to tackle games.
As far as writing lots of code, then "splitting it into separate files later" , I would strongly recommend that you have separate files as early as possible. Leaving it for later is just going to make things harder. Try to avoid big and complicated, rather aim for lots of small simple and reusable tools.
Any way Good Luck !! :+)