www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/01/09:56:32.1

From: "Floris van den Berg" <remu AT multiweb DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Initializing classes within classes...
Date: 1 Jan 1999 14:38:43 GMT
Organization: News Service (http://www.news-service.com/)
Lines: 53
Message-ID: <01be3595$06de8c40$617e97c2@fvdberg.magenta.com>
References: <368B7001 DOT 4A2F86FA AT wxs DOT nl>
NNTP-Posting-Host: 194.151.126.97
X-Newsreader: Microsoft Internet News 4.70.1155
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

That would be something like this:

class BASIC
{
private: // Lots of variables here...
public:
   BASIC( int a, int b);
};

class NOTSOBASIC
{
private:
  BASIC b1(1, 2);
  BASIC b2(3,4);
public:
  NOTSOBASIC() { /* how to init b1 and b2? */ }
};

Ofcourse it isn't really handy to declare the object with fixed parameters
like this. You could make a constructor BASIC::BASIC() - *without*
parameters - and do the handle handling from a separet method, like this:

class BASIC
{
private: // Lots of variables here...
  int ba, int bb;
public:
   BASIC();
   Create( int a, int b);
};

BASIC::Create(int a, int b)
{
  ba = a;
  bb = b;
}

class NOTSOBASIC
{
private:
  BASIC b1;
  BASIC b2;
public:
  NOTSOBASIC(int a, int b)
};

NOTSOBASIC::NOTSOBASIC(int a, int b)
{
  b1.Create(a, b);
  b2.Create(a, b);
}

Floris

- Raw text -


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