Skip to main content
GameDev.net gamedev.net
🔒 Locked

c++ include issues

Started by paws1111 Jun 25, 2007 at 10:36 PM 1 replies 750+ views
Original Post
paws1111
paws1111
Im makeing jump to c++ (from c# and java) and so i started a program in C++ and im haveing some issues with include's any how i have 2 classes mainForm includes Register.h (a panel to be swapable with other panels on runtime) and Register includes mainForm.h but this causes errors at the line of this code snipit in class1 this->window =((System::Windows::Forms::Panel^) gcnew Register()); and gives this error error C2061: syntax error : identifier 'Register' what about includes am i not understanding? why cant 2 classes include each other? and how can i get around this problem btw i need Register panel to include mainForm for typecasting so i can relay information gatherd in the registerpanel back to the mainForm
jebus11
jebus11
Looks like the problem is in how you've handled your header files. Unlike java c++ isn't very good at checking what has or has not been defined when its running through and compiling your code, so you have to watch out where you put your #includes.
Here's an example...

first.h:
#include "second.h"...(code that uses stuff from second.h)...


second.h:
#include "first.h"...


When the compiler goes through 'first.h', it will see the include for 'second.h' and jump there. But when it sees the include for 'first.h', it will jump back - without looking at anything! As a result, code in 'first.h' will come up with errors because the compiler doesn't know anything about 'second.h'.

Google should give you a few tutorials about the proper use of header files in c++. You might also want to read about how they are used with classes (more fun).

EDIT: Didn't have to look far [wink]
paws1111
paws1111
thanks a bunch il look into it tomarow when im less tyard :P

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.