www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/07/17:52:33

From: md2828 AT mclink DOT it (Marco Salvalaggio)
To: r DOT humphris AT indigo-avs DOT com
Cc: djgpp AT delorie DOT com
Subject: Re: HELP - need help resolving conundrum with classes
Date: Fri, 07 Mar 1997 22:31:44 GMT
Message-ID: <3323973a.7457205@newmail.mclink.it>
References: <c=GB%a=_%p=Indigo_Active_Vi%l=CRIANLARICH-970306153320Z-141 AT crianlarich DOT Indigo>
In-Reply-To: <c=GB%a=_%p=Indigo_Active_Vi%l=CRIANLARICH-970306153320Z-141@crianlarich.Indigo>
MIME-Version: 1.0

On Thu, 6 Mar 1997 15:33:20 -0000, you wrote:


>Sorry, but you are wrong, the code example shows you declaring an
>instance of the owner class, a prototype
>is done before the class is defined or instanciated, you will more often
>than not have such prototypes in=20
>header files so that other classes can use their type, and compile
>modularly.
>
>Rob Humphris
>
The example can't work 'cos the compiler doesn't have a chance of
determining the actual class size (I mean the first declared one,
the_cat) , the forward declaration doesn't carry enough information
for this.=20

The only way to get the program work is to forward declare the_owner
and then use a pointer (or a reference) to the_cat, this way:

class the_owner;

class the_cat
{
     the_owner *its_owners;
    // other stuff
   ....
};

class the_owner
{
    the_cat cats_owned[5];

   // other stuff
  ....
};


Marco

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019