0

Why cant I create a instance of the class Bor in Consumer? Look at the following reduced example.

##main.cpp
#include "Consumer.hpp"
#include "Bor.hpp"
int main(int argc, char** argv) {
    Bor bor;
    return 0;
}

This here is the consumer:

##consumer.cpp

#include "Consumer.hpp"
#include "Bor.hpp"
Consumer::Consumer(Bor& bor) :
bor(bor) {}
void Consumer::startConsumeLoop() {}

The consumers header:

##consumer.hpp

#ifndef CONSUMER
#define CONSUMER
#include "Bor.hpp"
class Consumer{
 public:
    Consumer(Bor& bor);
    void startConsumeLoop();
 private:
    Bor& bor;
};
#endif

This is the Bor:

##Bor.cpp

#include "Bor.hpp"
#include "Consumer.hpp"
Bor::Bor(){}

The bor header:

##Bor.hpp

#ifndef BOR
#define BOR
#include "Consumer.hpp"
class Bor{
 public:
    Bor();
};
#endif

Here is the command i run to compile:

clang++ -std=c++11 Consumer.cpp Main.cpp Bor.cpp

and the error:

./Consumer.hpp:6:11: error: unknown type name 'Bor'
        Consumer(Bor& bor);
./Consumer.hpp:8:2: error: unknown type name 'Bor'
        Bor& bor;
jonsk
  • 1
  • 3
    Circular include files. Get rid of `#include "Consumer.hpp" in `Bor.hpp`, since nothing in `Bor.hpp` depends on consumer.hpp. – Thomas Matthews Mar 09 '15 at 20:21

1 Answers1

3
  • Bor.hpp should not have #include "Consumer.hpp".
  • consumer.hpp may just have forward declaration of class Bor instead of include.
Jarod42
  • 203,559
  • 14
  • 181
  • 302