I have just started learning C++ and have been getting a lot of these errors. I finally found a solution to this after spending some time on the internet.
Say for instance you have a class called “Animal” and g++ complains that this class is being redefined. Just add the following two lines at the very top of the Animal.h file:
and add the following at the very bottom of the file:
So, if your class is called SomeClass, then it will be SOMECLASS_H instead of ANIMAL_H. You should have these in every header file. It prevents that header file from being redefined more than once.