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:
#ifndef ANIMAL_H
#define ANIMAL_H
and add the following at the very bottom of the file:
#endif
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.
No comments:
Post a Comment