Including headers in my project

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Ben said:
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.

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;
};
 
Back
Top