delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/18/11:20:47

From: "Niklas Pettersson" <npedt97 AT student DOT vxu DOT se (nospam)>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: c++
Date: Fri, 18 Feb 2000 07:43:41 +0100
Organization: Lund Institute of Technology, Sweden
Lines: 109
Message-ID: <88ipn9$7su$1@news.lth.se>
References: <A34D5D3BF0DFD2119E3D0008C70840FA04FD8B AT TWZNT11>
NNTP-Posting-Host: npedt97.univ.vxu.se
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

You can use an initializer list...

class Desktop
{
 public:
    Desktop();

    Panel Menu; // (0,0,100,100);
   Panel Icon;  // (0,100,100,100);
}

Desktop::Desktop() : Menu(0,0,100,100), Icon(0,100,100,100)
{
}

In this way, the Menu and Icon objects are initialized before the Desktop
object and you will not get an
ANSI C++ error..

/ Pson




"Nigel Atkinson" <Nigel DOT Atkinson AT MeridianEnergy DOT co DOT nz> wrote in message
news:A34D5D3BF0DFD2119E3D0008C70840FA04FD8B AT TWZNT11...
> Here is a solution, I think there is a better way, but this will work.
>
> Define another contstuctor for Panel that dose nothing.
>
> Panel() { return }
>
> You now can in Desktop write...
>
> class Desktop{
>  public:
>   Panel Menu;
>   Panel Icon;
> }
>
> without any errors.
>
> Now add a contstuctor to desktop like....
>
> Desktop()
> {
> Menu.Panel( 0, 0, 100, 100 );
> Icon.Panel( 0, 100, 100, 100 );
> return;
> }
>
> Like I said there is a better way - (which has escaped me at present) -
but
> this should get you going.
>
> Nigel Atkinson
>
>
> -----Original Message-----
> From: Jean-Francois Desjardins [mailto:jfd50 AT videotron DOT ca]
> Sent: Thursday, 17 February 2000 13:54
> To: djgpp AT delorie DOT com
> Subject: c++
>
>
> Hello!
> I want to know how I can initialize an object, within an object:
> ex:
>
> class Panel{
> private:
>  char xPos;
>  char yPos;
>  char Length;
>  char Width;
> public:
>  Panel( char X, char Y, char Len, char Wid);
>  ~Panel();
> };
>
> Panel( char X, char Y, char Len, char Wid);{
>  xPos=X;
>  yPos=Y;
>  Length=Len;
>  Width = Wid;
> }
>
> class Desktop{
>  public:
>   Panel Menu(0,0,100,100);
>   Panel Icon(0,100,100,100);
> }
>
>  that way, it give me an ANSI c++ error.
>
> I know if I do
> int main(void){
>  Panel Menu(0,0,100,100);
>  return(0);
> }
>
> without the Desktop class it will work, but I can't do that... I need the
> desktop class.
>
> Can anyone help please? thanks
>
>


- Raw text -


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