Question: C++ I have a factory method in my base class which returns a class pointer to one of two derived classes. I'm supposed to create
C++
I have a factory method in my base class which returns a class pointer to one of two derived classes. I'm supposed to create a virtual destructor. My question is what is this virtual destructor supposed to do. Here is the code for my factory method (inside the base class).

My previous lesson didn't deal with pointers so my previous destructor was just an empty destructor. Now, since the new method is a factory method and deals with pointers, I need a virtual destructor. How is that different than a regular destructor and this time I'm assuming I need to add something to it, instead of just an empty destructor.
Pet *Pet::create(string filename) f ifstream ifs(filename); string line getline(ifs, line) ifs.close); if (line"Cat") return new Cat(filename); if(line = "Dog" ) return new Dog(filename); return nullptr
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
