Sign in to follow this  
Calin

Classes and header files *Solved*

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 this post


Link to post
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

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this