1) It's not in the code, but one of the things I was thinking of doing was allocating a default block of memory for the array if no dimensions were specified. |
I'm not sure there's much point doing that. You wouldn't use that memory until you assign row and column sizes, at which point you'd probably have to reallocate the memory anyway.
If there's no need for a default constructor, there's no harm in doing away with it completely.
2) I have not come across the Rule of Three, copy constructors or assignment operators. These are completely new concepts to me. |
Copy constructors are worth looking at. Basically, they're just a type of constructor that takes, as its argument, an existing object of the same type. The idea is that you're constructing an object that is initialised in such a way that it's a copy of another object. There's nothing particularly advanced about it.
Overloading operators is a slightly more advanced topic, and you can probably wait until you reach it as part of your normal learning. Basically, I'm talking about creating a special version of the "=" operator that works for whole objects.
3) Yet another thing I haven't yet covered are exceptions and exception handling, that's why(for now) I've used the
nothrow
version of new[]. |
Fair enough. Exception handling is definitely an advanced topic, so don't worry about it now. Although really, my point was that you have a scenario in which your
draw() and
display() methods are unsafe, because they could be called with non-zero
row and
column, but a NULL
grid pointer.
4) Yes, they are only used as loop counters, but what's wrong with making them member variables? This way they don't need to be re-declared every time I may want to use them in a new function. |
As a general rule, you should keep variables/objects to as limited a scope as possible. This has several advantages:
- it makes it clear what the lifespan of any given variable is, and where its value might be used
- it prevents coupling between different parts of code that have no need to be coupled
- it stops you accidentally using a value that's still stored in the variable from a previous, unrelated use
As it is I'm looking at tutorials online, but it's tough going as many language concepts are not explained very clearly. |
I know the lure of free online stuff is strong but, really, you can't overstate the importance of a good, well-written book written by a professional writer who (a) knows their subject, and (b) knows how to present it clearly to their reader.
Without wishing to belittle the efforts of tutorial writers, online tutorials are often written by enthusiasts, in their spare time. They're very unlikely ever to give you teaching as good as that which you'll get from a dedicated professional.