By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

Problems with cross references

P: 2
Hello all,

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
  1. #include "../simulationManager/Simulation.h"
  2.  
  3. class IOutput{
  4.     public:
  5.         //Opens the necessary files for the execution given a filename.
  6.         virtual int openFiles(){};
  7. ...
  8. };
  9.  
  10. //class IControlSimulation; [A]
  11. //class InputSimulation; [B]
  12. class ConsoleOutputManager : public IOutput{
  13.     private:
  14.         //Control simulation
  15.         IControlSimulation *control;
  16. ...
  17.  
  18.     public:
  19.         ConsoleOutputManager(){
  20.             control = new InputSimulation();
  21.         }
  22. ...
  23. };
  24.  
  25.  
Simulation.h:
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include "../console/Console.h"
  3.  
  4. class IControlSimulation{
  5. public:
  6.     //Stops the simulation
  7.     virtual void stopSimulation(){}
  8. ....
  9. };
  10.  
  11. class InputSimulation : public IControlSimulation{
  12. private:
  13.  
  14.     //Event manager
  15.     SimulationEvents * simulator;
  16. ...
  17. };
  18.  
  19. class SimulationEvents{
  20. private:
  21.     //Output manager
  22.     OutputManager * output;
  23. ...
  24. };
  25.  
  26. class OutputManager{
  27. private:
  28.     //Console for output
  29.     IOutput * console;
  30. ...
  31. public:
  32.     OutputManager(){
  33.         console = new ConsoleOutputManager();
  34.     }
  35. ....
  36. };
  37.  
  38.  
So, when I try to compile this code (with declarations A and B comented) I get the following error:

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.
Jun 25 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
This error:
[quote=akilascartas]
console/../simulationManager/Simulation.h:19: error: ISO C++ forbids declaration of `IOutput' with no type
[/code]

says there is a problem on line 19 of Simulation.h.

This must be fixed first.

The addtional errors become less and less meaningful as the compiler becomes more an more confused.

You fix the first error. The rebuild. Then fix the first error. Then rebuild, etc.
Jun 25 '07 #2

P: 2
The point is that this error comes from Console

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


I mean, I think that the compiler compiles first Console (indeed it does), it reaches the "#include "../simulationManager/Simulation.h"" clause and it goes to Simulation.h before reaching IOutput in Console.h. Then, I suppose IOutput is unknown when it is compiling the OutputManager class (which contains IOutput) and this error is get.

I have just tried to make a forward declaration of IOutput (and ConsoleOutputManager, its subclass) and I get again this error:

In file included from console/Console.h:11,
from console/Console.cc:1:
console/../simulationManager/Simulation.h: In constructor `OutputManager::OutputManager()':
console/../simulationManager/Simulation.h:29: error: invalid use of undefined type `struct ConsoleOutputManager'
console/../simulationManager/Simulation.h:16: error: forward declaration of `struct ConsoleOutputManager'


Maybe the forward declarations were put before in the wrong side (declaring Simulator on Console side), but now the errors are the same :(

Thank you.

Diego
Jun 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.