![]() |
| ||
| C++ Beginner - #include recursion problem I am new to C++ and cant get my program to compile because of #include recursion. I have 3 classes A, B, C. A includes B.h and C.h B includes A.h C includes A.h and B.h They include each other because they either need to send messages between themselves. No inheritance is involved. I've tried using: #ifndef #define ......... #endif but because A and B are included twice they dont get included the second time. Any ideas for a C++ beginner who's spent the last 2 days trying to botch something togeather? Thanks, James |
| ||
| Re: C++ Beginner - #include recursion problem Can you give an example of how your headers look instead of just which includes the other? |
| ||
| Re: C++ Beginner - #include recursion problem As they stand they just recur: #include "Lift.h" #include "Control.h" class Floor { public: Floor(void); ~Floor(void); private: Control control;//to send requests }; #include "Floor.h" #include "Lift.h" class Control { public: Control(); ~Control(void); private: Floor floor;//to update floor display Lift lift;//to tell lift what to do }; #include "Control.h" class Lift { public: Lift(); ~Lift(void); private: Control control;//to send requests }; |
| ||
| Re: C++ Beginner - #include recursion problem If you want your classes to use each other, you pretty much need to do something like this using forward declarations and pointers (preferably smart pointers as they make your life easier): #ifndef FLOOR_H #ifndef CONTROL_H #ifndef LIFT_HIf you don't want to do that, you would be better off restructuring the classes so that they don't depend on each other: class FloorControl manipulates Lift through the Lift public interface and Lift manipulates the array of Floor through the Floor public interface. Any messaging is done that way. Of course, I don't know how your design is set up, so this suggestion may not work without significant changes. |
| ||
| Re: C++ Beginner - #include recursion problem Thanks for your help. That was really giving me a headache James |
| All times are GMT -4. The time now is 3:00 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC