Advertisement

class to class to class

Started by January 27, 2001 07:10 PM
1 comment, last by cyberg 24 years ago
hello, i have this case: class class1{ class2 cls2; }; class class2{ class1 cls1; }; i dont know how to make the class1 see the class2 and vice versa at the same time, anyone know how to do that? thx, cyberg
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft
All you have to do is to use a FORWARD DECLARATION of the second class. That is, your DECLARE that the class exists but you''ll DEFINE it somewhere else.

  // Forward declaration.class C2ndClass;// Define the 1st class...class C1stClass {    C2ndClass m_2ndClass;};// ... and the 2nd too...class C2stClass {    C1stClass m_1stClass;};  


Hope it helps...


Karmalaa






[home page] [e-mail]

---
"Lifting shadows off a dream once broken
She can turn a drop of water into an ocean"
---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]
Advertisement
dude... I think what you want is for each class to have a *pointer* to the other. If a class1 object has a class2, and that has a class1, and that has a class2... It''s a recursive definition. That why you''re not allowed to say

class InfiniteClass
{
public:

InfiniteClass Infinity;
};

You see what I mean? But it''s legal to say

class OKClass
{
public:

OKClass *GoodEnough;
};

Hope I helped...
"The reasonable man adapts himself to the world, butthe unreasonable man tries to adapt the world to him-therefore, all progress depends on the unreasonable man." -Samuel Butler

This topic is closed to new replies.

Advertisement