Skip to main content
gamedev.net
🔒 Locked

more pointers

Started by uncutno Apr 11, 2002 at 5:22 PM 3 replies 450+ views
Original Post
uncutno
uncutno
Is this in any way posible?
  
class COne{
public:
     CTwo *link;
};

class CTwo{
public:
     COne *link;
};
  
i want both the child and the parenth to have a pointer to the other inside... pleace help!
-Anders-Oredsson-Norway-
Palidine
Palidine
yep is possible though why you''d want it is mysterious.


//forward decleration
class CTwo;

class COne{
public:
CTwo *link;
};

class CTwo{
public:
COne *link;
};
blahpers
blahpers
There are perfectly valid reasons for it.

Say you have your game objects arranged into systems (e.g., particle or similar systems, in which objects are individual but related). Additionally, though, any object can have child object systems. An example might be a Object "sun" with a child ObjectSystem containing the Objects "mars","venus", and so forth; each planet would have a subsystem containing its moons, and so forth.

class Object;
class ObjectSystem;

class Object
{
// ...
ObjectSystem* subSystems;
};
class ObjectSystem
{
// ...
Object* objects;
};


It's not the only way to do things, but it's a good one for some purposes (like preserving relationships between objects in a system).

[edit]code tag[/edit]

---
blahpers

[edited by - blahpers on April 11, 2002 11:01:08 PM]
---blahpers
Chem0sh
Chem0sh
You can also have:


    
class COne
{
public:
class CTwo *link;
};

class CTwo
{
public:
class COne *link;};


/*=========*/
/* Chem0sh */
/*=========*/

[edited by - Chem0sh on April 12, 2002 8:15:45 AM]
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
stefandxm
stefandxm
another good example where stuff like this always is needed :

crappymath.h

vector vs matrix (mul = transform etc)
matrix vs vector (mul = scale etc)
matrix vs quaternion ( ''='' = quaternion to matrix etc)
quaternion vs matrix ( ''='' = matrix to quaternion etc)

well just a few examples of that its NOT a hack to do stuff like that.. its really needed in objectoriented programming
--mega!--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.