473,387 Members | 1,495 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,387 software developers and data experts.

Cross-referencing in Headers

I am having trouble with headers at the moment. Here is the code for a
start:

body.h:

#pragma once

#ifndef BODY_H
#define BODY_H

class body
{
private:
joint* jointList;
};

#endif

joint.h:

#pragma once

#ifndef JOINT_H
#define JOINT_H
class joint
{
public:
int getRelativeX(){return r_X;}
int getRelativeY(){return r_Y;}
private:
//The x variable is actually relative to the master body
int r_X;//Relative X
int r_Y;//Relative Y
body* r_Body;//Relative Body
};

#endif

main.cpp:

/*--------Declarations--------*/

#include <iostream>

#include "joint.h"
#include "body.h"

using namespace std;

int main()
{
cout<<"Hello World";
cin.get();
return 1;
}

Now the problem I am encountering is that when I compile this it has
errors with the following line:

body* r_Body;//Relative Body

I know this is because somehow the headers haven't linked properly.
The problem is that joint needs body and body needs joint. So how
would I do this, because I'm stumpted. Thanks for your help in advance.

Jun 17 '07 #1
2 1379
ADT_CLONE wrote:
I am having trouble with headers at the moment. Here is the code for a
start:

body.h:

#pragma once

#ifndef BODY_H
#define BODY_H

class body
{
private:
joint* jointList;
};

#endif

joint.h:

#pragma once

#ifndef JOINT_H
#define JOINT_H
class joint
{
public:
int getRelativeX(){return r_X;}
int getRelativeY(){return r_Y;}
private:
//The x variable is actually relative to the master body
int r_X;//Relative X
int r_Y;//Relative Y
body* r_Body;//Relative Body
};

#endif

main.cpp:

/*--------Declarations--------*/

#include <iostream>

#include "joint.h"
#include "body.h"

using namespace std;

int main()
{
cout<<"Hello World";
cin.get();
return 1;
}

Now the problem I am encountering is that when I compile this it has
errors with the following line:

body* r_Body;//Relative Body

I know this is because somehow the headers haven't linked properly.
The problem is that joint needs body and body needs joint. So how
would I do this, because I'm stumpted. Thanks for your help in advance.
You need forward declarations

#ifndef BODY_H
#define BODY_H

class joint; // forward declaration

class body
{
private:
joint* jointList;
};

#endif

#ifndef JOINT_H
#define JOINT_H

class body; // forward declaration

class joint
{
public:
int getRelativeX(){return r_X;}
int getRelativeY(){return r_Y;}
private:
//The x variable is actually relative to the master body
int r_X;//Relative X
int r_Y;//Relative Y
body* r_Body;//Relative Body
};

#endif

john
Jun 17 '07 #2
On Jun 17, 6:00 pm, John Harrison <john_androni...@hotmail.comwrote:
ADT_CLONE wrote:
I am having trouble with headers at the moment. Here is the code for a
start:
body.h:
#pragma once
#ifndef BODY_H
#define BODY_H
class body
{
private:
joint* jointList;
};
#endif
joint.h:
#pragma once
#ifndef JOINT_H
#define JOINT_H
class joint
{
public:
int getRelativeX(){return r_X;}
int getRelativeY(){return r_Y;}
private:
//The x variable is actually relative to the master body
int r_X;//Relative X
int r_Y;//Relative Y
body* r_Body;//Relative Body
};
#endif
main.cpp:
/*--------Declarations--------*/
#include <iostream>
#include "joint.h"
#include "body.h"
using namespace std;
int main()
{
cout<<"Hello World";
cin.get();
return 1;
}
Now the problem I am encountering is that when I compile this it has
errors with the following line:
body* r_Body;//Relative Body
I know this is because somehow the headers haven't linked properly.
The problem is that joint needs body and body needs joint. So how
would I do this, because I'm stumpted. Thanks for your help in advance.

You need forward declarations

#ifndef BODY_H
#define BODY_H

class joint; // forward declaration

class body
{
private:
joint* jointList;

};

#endif

#ifndef JOINT_H
#define JOINT_H

class body; // forward declaration

class joint
{
public:
int getRelativeX(){return r_X;}
int getRelativeY(){return r_Y;}
private:
//The x variable is actually relative to the master body
int r_X;//Relative X
int r_Y;//Relative Y
body* r_Body;//Relative Body

};

#endif

john

Oh ok, thanks a lot. I thought it was something like that. I'm a bit
rusty and was trying to do it the wrong way. :D

Jun 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
3
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
6
by: Simon | last post by:
Hi All, An experiment i'm doing requires requires a synchronous cross-domain request, without using a proxy. I wondered if anyone had any ideas to help me achieve this. Below is what I have...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.