468,768 Members | 1,669 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,768 developers. It's quick & easy.

Including headers in my project

Ben
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
Nov 17 '05 #1
1 972
Ben wrote:
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;
};

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Billy Jacobs | last post: by
11 posts views Thread by cppaddict | last post: by
8 posts views Thread by Abubakar | last post: by
5 posts views Thread by =?Utf-8?B?SmltbWVy?= | last post: by
8 posts views Thread by J Kenneth King | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.