lundi 9 mars 2015

Creating instance of codependant classes C++11 [duplicate]


This question already has an answer here:




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;

Aucun commentaire:

Enregistrer un commentaire