Hi,
Edit: Ninja'd - hopefully some of it is worthwhile :+)
If I could add my 2 cents worth, to help you out now. The very knowledgeable / expert
keskiverto ,
James2250 ,
MikeyBoy haven't replied for awhile (different time-zone). I am just a dabbler, you should prefer to deal with these guys :+)
If one doesn't supply a destructor, then the compiler will implicitly create one for you. Presumably, it goes through and properly destroys each member in your object. So I guess this is why it works when you don't have a dtor.
When you do supply a dtor that does nothing, I imagine that MSVC is complaining about members of of your object not being destroyed properly.
I just heard that classes should have destructors and that not having them could lead to memory leaks. |
That applies if you are allocating on the heap as opposed to on the stack. There are other situations too, like if you have virtual functions - you should provide a virtual dtor. If none of that applies to you, then you may well not need a destructor. Even if you do need one, you can force default behaviour with this:
~Player() = default; // C++11
Just some other stuff I can see about your code already, nothing to do with your problem, just mentioning them to help you out, or give a different insight:
Learn about constructor initialiser lists, and how they are better than the assignment you are doing at the moment. Also about default values. Here are some partial examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// initaliser list
Player::Player (
// Base class parameters here
std::string name = "Ginger"; // parameters in same order as class declaration, don't miss any of them
char gender = 'F'; // put comments about valid range of values
int age = 20; // could be unsigned short??
int level = 1; // could be unsigned short??
int Xp; // other default vlaues
int search;
// and so on ......
)
: // colon introduces initilaser list - values initialised before object is created
// call base class constructors here, in order
m_name(name);
m_gender(gender);
m_age(age);
m_level(level);
m_Xp(Xp);
m_search(search);
// and so on .....
{
// do some validation checks here, set member IsValid to false, report error or throw exception
// or more advanced do a function try block in initialiser list as well
} // end constructor body
|
Also, One can use brace initialisation for arrays, as in :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// compiler will count how items there are in array
std::string m_skills[] = { "Survival :" , //Spread things out 1 per line then you can comment them if necessary
"First Aid :" ,
"Hunting :" ,
"Search :" ,
"Pistals :" ,
"Rifles :" ,
"Melee :" ,
"Stealth :" ,
"Lockpicking :" ,
"Toughness :" ,
"Stiking :" ,
"Explosives :"
};
|
Why is this array a member of the Player class? Could it be a
struct
that has other variables associated with each array item? For example a
bool
to say whether Player owns a thing or not.
Good luck !! :+D