Finding the bug

Hello, im currently learning c++ and one of the exercises I was given is to find the bug in the following code. I could not figure out what the bug was, other than maybe because the pointer was not deleted and might cause memory leaks, but it should not matter because the program was returning anyways.

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
#include <iostream>
using namespace std;

class CAT
{
public:
	CAT(int age) { itsAge = age; }
	~CAT() {}
	int GetAge() const { return itsAge; }


private:
	int itsAge;

};

/*---------------------------------------------------------------------------------------------------*/

CAT &MakeCat(int );

int main()
{
	int age = 8;
	CAT Boots = MakeCat(age);
	cout << "Boots is " << Boots.GetAge() << " years old" << endl;
	system("pause");
	return 0;

}

CAT &MakeCat(int age)
{
	CAT *pCat = new CAT(age);
	return *pCat;

}
Last edited on
Topic archived. No new replies allowed.