I've got this error "error:expected class-name before '{' token". Let me explain you how to debug this, so keep following the comments in each line.
Let's see the simplified version of the solution before jumping into the higher version.
Colors.h
#include <iostream> class Colors : public Nailpolish { };
The above code leads to this error
Line 3: error: expected class-name before '{' token
#include <iostream> #include "Nailpolish.h" class Colors : public Nailpolish { };
Including the 'Nailpolish.h' in which the Nailpolish class is defined, solves the issue.
Let's see the higher version now.
// Preprocessing will start here #ifndef GROUP_H_ // It is not defined yet, so keep going #define GROUP_H_ #include "Assessment.h" #include "Task.h" // include #include "Alienate.h" // Go to Alienate. h file class Group : public Assessment { public: Group(Task* task, int time); virtual ~Group(); protected: /* Due to the below line, I included Alienate.h */ Alienate* createNewAlienation(Separate* separate); / private: Task* task; int time; // when this task will complete occurs }; #endif /* GROUP_H_ */
#ifndef ALIENATE_H_ // It lands here, it is not defined yet, keep going #define ALIENATE_H_ #include "Group.h" // It goes back to group.h, but it is already defined class Alienate: public Group { // It doesn't know what is group public: Alienate(Task* task, int time); virtual ~Alienate(); }; #endif /* Alienate_H_ */
So, before coming to alienate.h, group class should be defined. This can be achieved by not including the alienate.h file, but including 'class alienate;' as a forward declaration which is not a definition.
Include this alienate.h file in group.cpp file.
Forward declaration should be included in the header files and #include should be done in the .cpp files.
Comments
Post a Comment