weird output when using delete

So I get some weird output to the cmd promt when running this.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
class Item{
protected:
	unsigned short int m_value;
	string m_name;
	unsigned short int 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:
	unsigned short int m_damage;
	unsigned short int 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.

any ideas???
Last edited on
Also, after I close the com prompt I get this error:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall MeleeWeapon::~MeleeWeapon(void)" (??1MeleeWeapon@@QAE@XZ) referenced in function "public: void * __thiscall MeleeWeapon::`scalar deleting destructor'(unsigned int)" (??_GMeleeWeapon@@QAEPAXI@Z) c:\Users\development\documents\visual studio 2013\Projects\classFun\classFun\classFun.obj classFun
NVM!

I forgot to include the body for the destructor... smh. its late.

for any one who stumbles upon this later the destructors should look like:
1
2
3
4
5
6
7

~MeleeWeapon(){};

// NOT like \/\/

~MeleeWeapon(); 


what I was doing was only declaring it and not defining it.
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.
Topic archived. No new replies allowed.