Jump to content
  • Advertisement
Sign in to follow this  
Calin

Classes and header files *Solved*

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!