Try not to get in the habit of using
using namespace std
. Read thisthis for more information.For clarity, have your
#include
s organized. Read this blog post or this answerthis answer for more information.Add a newline between each section of code. For instance, separate all user input and loops. For variables, it's best to initialize them late as late as possible in case the function needs to terminate prematurely. Again, keep them with the corresponding code.
mobclass.h
already includes<string>
, so you don't need to include it again in the .cpp file.You have a lot of accessors and mutators. Since these are short one-line implementations, you can define them in the header like this:
void setEXP() {EXP = (getlevel() * 35;} int getEXP() const {return EXP;}
As such, you will no longer need to implement these in the .cpp file. When they're in the header, they'll automatically be
inline
. It should also make it easier if you ever need to implement newer functions. In the header, you could also keep the accessors and mutators together for clarity.I like what @Kaivo Anastetiks said about
classMob
's constructor, but I would like to add on that a bit. You have a few options for this: