class Item{
protected:
unsignedshortint m_value;
string m_name;
unsignedshortint m_type;
public:
Item(int itemCreating){
//---NA---
}
~Item();
int getValue(){ return m_value; }
string getName(){ return m_name; }
int getType(){ return m_type; }
};
class MeleeWeapon : public Item{
private:
unsignedshortint m_damage;
unsignedshortint m_weaponRef;
public:
MeleeWeapon(int itemCreating) : Item(itemCreating){
//---NA---
}
~MeleeWeapon();
int getDamage(){ return m_damage; }
};
int main()
{
MeleeWeapon * pPipeWrench = new MeleeWeapon(PipeWrench);
delete pPipeWrench;
return 0;
}
output says:
'"c:\users\dev\documents\visual studios\Projects\class fun\Debug\classFun.exe"' is not recognized as an internal or external command, operable program or batch file.
------------------------------------------
I don't know if I am properly deallocating pPipeWrench or not. I have googled destructors in c++ many times and to me it looks like I am doing it right.
If I dont use the delete operator the program runs.
You should initialize the [POD] member variables (m_value/m_type).
If you don't need a destructor you don't need to declare one. However it is wise to have virtual destructor for the base class. Otherwise the destructors of the inherited classes might not be called.