Jump to content
  • Advertisement
Sign in to follow this  
thecoast47

Preprocessor Question [c++]

This topic is 2593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[SOLVED]
So I’m merging two 2D physics engines I wrote. One physics engine handled rigid bodies and the other handled soft bodies.
My convex hull class has an array of edges and points. The thing is, I want those Edge and point objects to have a reference to the parent convex hull object. This is where the preprocessor will tell me that I have nested my includes too deeply. I really don’t know how to get around this problem because i have a very limited knowledge of the preprocessor.

Here is some code to give you an idea of what is going on:


class Vector2D{
public:
float X;
float Y;
ConvexHull * Parent;
//Vector Operations...
};
class Edge{
public:
Vector2D * P1;
Vector2D * P2;
ConvexHull * Parent; //<-----This is what i need in my EdgeClass
};


class ConvexHull{

public:

std::vector<Edge*> EdgeList;
std::vector<Vector2D*>PointList;



};


Share this post


Link to post
Share on other sites
Advertisement
You want a forward declaration: put "class ConvexHull;" before Edge. Note that this wouldn't work if you wanted a ConvexHull value (rather than pointer) member of Edge.

EDIT: Although, this doesn't have anything to do with includes or the preprocessor. Do you have include guards on your headers?

Share this post


Link to post
Share on other sites

EDIT: Although, this doesn't have anything to do with includes or the preprocessor. Do you have include guards on your headers?


if you mean:
#ifndef ....
#define....
...
...
...
#endif
then yes.
if those arent the include gards then i guess i dont have them..

Share this post


Link to post
Share on other sites
The design seems suspicious. I cannot image why those types require pointers to their parent objects.

You should be able to fix this by using a forward declaration of ConvexHull from the Vector/Edge header files, while also removing any direct or indirectly included #include "Convex_Hull.h" directive from this header, moving it to the Vector/Edge source files if required.

Share this post


Link to post
Share on other sites

The design seems suspicious. I cannot image why those types require pointers to their parent objects.


The collision response of soft bodies uses this method.
I dont fully understand why it works the way it does but the important thing is that it works.
If you find a better way of doing soft bodies in 2D please tell me.

Share this post


Link to post
Share on other sites
I only skimmed the article, but I see nothing that requires the Vector or Edge types to have a pointer to their parent object.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!