Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

Including headers in my project

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben - 02 Feb 2005 12:41 GMT
Hi guys, this *should* be a simple problem, but I've never really got my head
around it. I'm hoping somebody on this message board could help me out? I
don't really have any experience with VS.NET, which is probably why I'm
having so much trouble!

Basically, I've been doing some OpenGL coding using VS.NET as the compiler.
Obviously (if you know any OGL), you'll know I need to include gl.h and glu.h
to have access to all the drawing functions.

Whilst I've been working through the tutorials, all of the code has always
been in a single .cpp file. The two .h files are included at the top, and
that's that. However, I've been trying to split up my classes into different
.cpp files, which has given me all sorts of problems.

If I include the headers at the top of main.cpp only, I get complaints from
the renderClass.cpp file saying that it can't find the definitions it needs.

If I include the headers at the top of renderClass.cpp only, I get all sorts
of errors INSIDE the header itself.  Apparantly there are lots of semi-colons
missing from gl.h, which I'm pretty sure there aren't!!

If I include the headers in both files, I get multiple definition errors all
over the place. If I try and use #ifdef and #ifndef then I find that the
defintions aren't made in the second file, so it's back to square one!

So, my question is... How do I go about including a header file into
multiple C++ sources, so that both .cpp files can use the information, but
avoiding multiple defintion errors?

I know this is elementary stuff, but I've never figured it out. Am I just
approaching this the wrong way? Thanks in advance to anybody who can help!

Cheers,

Ben
Mihajlo Cvetanovic - 02 Feb 2005 14:41 GMT
> Basically, I've been doing some OpenGL coding using VS.NET as the compiler.
> Obviously (if you know any OGL), you'll know I need to include gl.h and glu.h
[quoted text clipped - 4 lines]
> that's that. However, I've been trying to split up my classes into different
> .cpp files, which has given me all sorts of problems.

I don't know especially for gl.h and glu.h but here's general advice. In
all your cpp files:

#include "stdafx.h"        // if you use it
#include "main_project.h"  // if you have it
#include "corresponding.h" // for X.cpp it's X.h

#include <whatever.h>      // if needed
#include "anything_else.h" // I guess gl.h and glu.h go here

In header files don't include more than you need. If you have a pointer
to an object of class SomeClass as a member of ThisClass then just use:

// ThisClass.h
class SomeClass; // that's all there is

class ThisClass {
  SomeClass* member;
};

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.