// Assume class definition for Cat is here.
Cat makeCat() {
Cat lady = new Cat("fluffy");
return lady;
}
int main (...) {
Cat molly = makeCat();
molly->eatFood();
return 0;
}
Will there be a “use after free” error on molly->eatFood()?
Corrected your program and created an example implementation of
class Cat:It will produce the output:
I suggest you learn a basic book about the C++ cover to cover before continuing.