There is an abstract class BasicUnit:

#pragma once #include "iostream" //file BasicUnit.h using namespace std; class BasicUnit { protected: int health; public: enum UnitType {Builder, Soldier, Town, Home}; virtual void showHealth(); BasicUnit(); BasicUnit(int a); virtual ~BasicUnit(); }; 

From it the Builder class is inherited:

  #include "BasicUnit.h" #include "Home.h" class Builder : public BasicUnit { public: Builder(); Builder(int a); int chopTree(); ~Builder(); Home buildHome(); // Ошибка здесь }; 

In the third class Home, I want to set the Builder as a return type, but the compiler gives an error that the Builder does not exist in BasicUnit.

 #include "BasicUnit.h" #include "Builder.h" #include "iostream" using namespace std; class Home : public BasicUnit { public: Home(); Builder createBulder(); //Ошибка здесь ~Home(); }; 

How to make a return type Builder? thank

  • Cyclic inclusion of header files. Get rid of the cyclic inclusion of header files. - AnT
  • @AnT tell me, where exactly is the cycle? The compiler does not swear. - Vadim Tor
  • Home and BasicUnit include each other. And he should not swear, formally it is not a mistake. - HolyBlackCat
  • @AnT as far as I understood that the whole problem was that Home.h was included in the Builder. Now the program works, but: the next step will be the createHome () function just in the Builder class, which will return the Home class. How to return the class Home, if it can not be connected? - Vadim Tor
  • Declare a Home class before the Builder class. Just declare, do not define. - ArtemLP pm

0