@JLBorges answered your question. However, you might want to consider the header files you included in your animal_factory.h. I don't see any mention of cats or dogs in your header, so there is no reason to include cat.h or dog.h. Additionally, since you only reference an Animal*, you can simply forward declare Animal rather than include the header file.
1 2 3 4 5 6 7
...
class Animal;
...
Animal* createAnimal(const std::string &, unsignedint);
...
These may seem like minor things, but as your programs get more involved, unnecessary headers can lead to unexpected dependencies which can cause rebuilds to take longer than expected. In worst cases, you can develop circular dependencies which can cause builds to fail. It's always best to limit the number of header files included in a header file.
Also, you include <cstring> which is (essentially) the C string.h file, but you are using C++'s std::string class. You should include <string> instead.
@doug4,
Thanks alot for taking out time for this insightful addition.
I'd be glad if you could let me know if we could do the intended thing without including these headers.
The intent of the program is to create a singleton factory (AnimalFactory) that returns an animal object pointer based on the string passed to createAnimal(....).
Is there a we do not need to include animal.h, cat.h, dog.h in the animal_factory.h file. I included them because Register function maps the values of string (animal family (cat or dog)) to the create function defined in that class.
Here is the code for reference, in case you would like to have a look.
Is there a we do not need to include animal.h, cat.h, dog.h in the animal_factory.h file. I included them because Register function maps the values of string (animal family (cat or dog)) to the create function defined in that class.
Yes. But you don't use them in the header file. You use them in the source file. Include them there.
So, in animal_factory.h, you can remove lines 5 & 6. In animal_factory.cpp you need to include them. Earlier I didn't notice the reference to CreateAnimalFn in animal.h, so you do need to include animal.h in animal_factory.h for that definition.