I have been facing a problem for several weeks with my C++ code. First of all, I am going to expose how my files/classes are written:
File ./SimulationManager/Simulation.h (with Simulation.cc in the same location, defining the functions)
Classes:
- IControlSimulation (virtual)
- InputSimulation : IControlSimulation -->contains a reference to IOutput (through InputSimulation, SimulationEvents and OutputManager)
File ./Console/Console.h (idem with Console.cc)
Classes:
- IOutput(virtual)
- ConsoleOutputManager : IOutput (Contains a reference to IControlSimulation)
Now, let us see the code of thes classes. Please, look at the forward declarations (points A and B)
Console.h:
Expand|Select|Wrap|Line Numbers
- #include "../simulationManager/Simulation.h"
- class IOutput{
- public:
- //Opens the necessary files for the execution given a filename.
- virtual int openFiles(){};
- ...
- };
- //class IControlSimulation; [A]
- //class InputSimulation; [B]
- class ConsoleOutputManager : public IOutput{
- private:
- //Control simulation
- IControlSimulation *control;
- ...
- public:
- ConsoleOutputManager(){
- control = new InputSimulation();
- }
- ...
- };
Expand|Select|Wrap|Line Numbers
- #include "../console/Console.h"
- class IControlSimulation{
- public:
- //Stops the simulation
- virtual void stopSimulation(){}
- ....
- };
- class InputSimulation : public IControlSimulation{
- private:
- //Event manager
- SimulationEvents * simulator;
- ...
- };
- class SimulationEvents{
- private:
- //Output manager
- OutputManager * output;
- ...
- };
- class OutputManager{
- private:
- //Console for output
- IOutput * console;
- ...
- public:
- OutputManager(){
- console = new ConsoleOutputManager();
- }
- ....
- };
In file included from console/Console.h:11,
from console/Console.cc:1:
console/../simulationManager/Simulation.h:19: error: ISO C++ forbids declaration of `IOutput' with no type
console/../simulationManager/Simulation.h:19: error: expected `;' before '*' token
console/../simulationManager/Simulation.h: In constructor `OutputManager::OutputManager()':
console/../simulationManager/Simulation.h:26: error: `console' undeclared (first use this function)
console/../simulationManager/Simulation.h:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
console/../simulationManager/Simulation.h:26: error: `ConsoleOutputManager' has not been declared
make[1]: *** [build/Release/GNU-Generic/console/Console.o] Error 1
If I let point A ("class IControlSimulation;"), the error is the following (I suppose this is obvious...):
In file included from console/Console.h:11,
from console/Console.cc:1:
console/../simulationManager/Simulation.h:19: error: ISO C++ forbids declaration of `IOutput' with no type
console/../simulationManager/Simulation.h:19: error: expected `;' before '*' token
console/../simulationManager/Simulation.h: In constructor `OutputManager::OutputManager()':
console/../simulationManager/Simulation.h:26: error: `console' undeclared (first use this function)
console/../simulationManager/Simulation.h:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
console/../simulationManager/Simulation.h:26: error: `ConsoleOutputManager' has not been declared
make[1]: *** [build/Release/GNU-Generic/console/Console.o] Error 1
And finally, with both lines uncommented:
In file included from console/Console.h:11,
from console/Console.cc:1:
console/../simulationManager/Simulation.h:19: error: ISO C++ forbids declaration of `IOutput' with no type
console/../simulationManager/Simulation.h:19: error: expected `;' before '*' token
console/../simulationManager/Simulation.h: In constructor `OutputManager::OutputManager()':
console/../simulationManager/Simulation.h:26: error: `console' undeclared (first use this function)
console/../simulationManager/Simulation.h:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
console/../simulationManager/Simulation.h:26: error: `ConsoleOutputManager' has not been declared
make[1]: *** [build/Release/GNU-Generic/console/Console.o] Error 1
Maybe the error is too obvious, but I cannot see it. If anybody could help me to solve it I would be very thankful.
Thank you all for your time (including the time spent reading this post :) )
Best regards,
Diego.