Hello, I'll try to explain this as best I can. I'm having trouble understanding what this code is...saying...It's just an example exercise from a book, but I'm not sure how to 'say' to myself what this code is doing. Specifically the lines that are commented.
#include <iostream>
#include <conio.h>
using namespace std;
class CAT
{
public:
CAT(int age) {itsAge = age;}
~CAT() {}
int GetAge() const {return itsAge;}
private:
int itsAge;
};
CAT &MakeCat(int age); //What is this 'saying'?
int main()
{
int age = 7;
CAT Boots = MakeCat(age);
cout << "Boots is " << Boots.GetAge() << " years old." << endl;
_getch();
return 0;
}
CAT &MakeCat(int age)
{
CAT *pCat = new CAT(age);
return *pCat;
}
//also, the code compiles but the book says there is an error
//probably a memory leak situation. Don't worry about it.
I understand it's saying it returns a CAT object, but is it saying it's a reference function or something, what does a reference function mean?
I hope you can understand what I'm trying to ask.
Thank you.






