473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1079
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
11
by: cppaddict | last post by:
Say that your CustomClass.h header files requires #include <string> Now say that your CustomClass.cpp file also requires string. Is it good form to repeat the <string> include to make the...
1
by: JoeS | last post by:
Is there anyway to share a single pch file between projects in VC 7.0? I have 300+ projects each of which creates its own pch. All projects include the exact same header files in the precompiled...
8
by: Abubakar | last post by:
Hi, I am writing some unmanaged c++ code that would need to be compiled in the future using compilers other than vc++. I'm using the feature of vc++ "use precompiled headers", is there going to...
3
by: Maciek | last post by:
All, I'm having a problem building a library (VMime) with Visual .NET 2003. It's including, among others, gnutls.h from the GNU TLS library and I'm getting syntax errors in that file. For...
1
by: Wizard1981 | last post by:
In order to structure my code I'm using different folder for my source and header files. Unfortunately, the builder would not find the included headers and output following error: fatal error...
5
by: =?Utf-8?B?SmltbWVy?= | last post by:
Hello, I've been trying to create a WCF SOAP Router Service that can forward not just the message body but also any security headers set by the originator of the message. The destination service...
8
by: nguillot | last post by:
Hello. If I have the following classes: class B {}; typedef B tB; if A is: class A
8
by: J Kenneth King | last post by:
Hey everyone, I'm working on a python extension wrapper around Rob Hess' implementation of a SIFT feature detector. I'm working on a computer-vision based project that requires interfacing with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.