• Popular Now

• 13
• 18
• 19
• 27
• 10

This topic is 4650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! My initial thought was to post my question in the General Programming forum but i think it is better to post it here. I am trying to make a game using OpenGL and my source code file got recently very large. I decided to split the file into several source files. Here is what i did: I placed the definition of a class named 'units' in 'units.h' and the implementation of that class in 'units.cpp'. In 'Draw.cpp' I created an array of objects of class 'units' called MyUnits. I defined another class called 'switch' in 'switch.h' file and placed the member functions implementation in 'switch.cpp'. At the beginning of 'Draw.cpp' I included 'switch.h' file and declared an object of class 'switch' named Switch1. Immediately after that (in 'draw.cpp') I made a call to a function that is a member of "switch" class passing as argument "MyUnits" ( object of class units). Here is the line of code I used: Switch1.InterpretSelection( MyUnits ); Finally I included the file 'units.h' at the top of switch.cpp and defined InterpretSelection so that it would accept MyUnits as argument: void InterpretSelection ( units Ut[] ); When I tryed to compile the code I recived a sintax error in 'switch.h' at the line where my InterpretSelection function was defined. Can someone help me with this one? P.S: Thank you for patience for reading so far. [Edited by - Calin on June 26, 2005 3:16:07 PM]

Share on other sites
You need to use the ifdef, define and endif macros in order to declare things once. For example:

//header file:#ifdef _YOURHEADERFILE_H#define _YOURHEADERFILE_H//insert class/object/function declarations here#endif//source file 1:#include "YourHeaderFile.h"//insert class functions/functions here//source file 2:#include "YourHeaderFile.h"//insert different class functions/functions here

Thanks!

Share on other sites
Also, you can't have a class named "switch", because that's a keyword in the language (as in switch constructs).

Share on other sites
Shouldn't those gaurds be:

#ifndef not #ifdef?

EDIT:

Sorry. Scratch that. Thought they were guards...they're not..:)