delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/31/16:25:00

Message-ID: <011d01be3502$f9d75c80$04a531ce@enterprise-w>
From: "Jorge Ivan Meza Martinez" <jimeza AT usa DOT net>
To: <djgpp AT delorie DOT com>, <jansb000 AT wxs DOT nl>
Subject: RE: Initializing classes within classes...
Date: Thu, 31 Dec 1998 15:59:06 -0500
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

Hi Jans,

try something like ...

( note the constructor for NoBase ).



#include <iostream.h>

class Base
{
public:
Base ( int a, int b )
     {
     cout << "( " << a << ", " << b << " )" << endl;
     }
};

class NoBase
{
private:
Base b0;
Base b1;

public:
NoBase ( char msg[] ) :
              b0 ( 2,3 ),
              b1 ( 5,6 )
       {
       cout << "mensaje = " << msg << endl;
       }
};

int main ( void )
{
NoBase k ( "MSG" );
}




    Jorge Ivan Meza Martinez
jimezam AT armenia DOT multi DOT net DOT co
           jimeza AT usa DOT net
       jimezam.home.ml.org

["O Lord, if there is a Lord, save my soul, if I have a soul--", Ernest
Renan]




-----Mensaje original-----
De: A. Jans-Beken <jansb000 AT wxs DOT nl>
Grupos de noticias: comp.os.msdos.djgpp
Para: djgpp AT delorie DOT com <djgpp AT delorie DOT com>
Fecha: Miércoles, 30 de Diciembre de 1998 10:08 p.m.
Asunto: Initializing classes within classes...


>I am wondering how to do this...
>
>class BASIC {
>   private: // Lots of variables here...
>   public: BASIC( int a, int b); // Constructor ...
>   };
>
>class NOTSOBASIC {
>   private:
>      BASIC b1;
>      BASIC b2;
>      // Many other variables...
>   public:
>      NOTSOBASIC() { /* how to init b1 and b2? */ }
>   };
>
>The class "NOTSOBASIC" contains two BASIC items. However, the BASIC
>items always must be constructed with two parameters. How must I program
>the constructor of "NOTSOBASIC" so that b1 and b2 are correctly
>initialized?
>
>thanx.
>
>

- Raw text -


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