delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/29/20:19:55

Date: Thu, 29 Jan 1998 19:20:13 -0600 (CST)
From: Andrew Deren <aderen AT eecs DOT uic DOT edu>
To: Chia <chia AT top DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Easy C++ stuff... I hope, anyway.
In-Reply-To: <6aolmn$3vs@nnrp3.farm.idt.net>
Message-ID: <Pine.GSO.3.96.980129191834.15622A-100000@bert.eecs.uic.edu>
MIME-Version: 1.0



                        ,,,
                       (0 0)
   +-------------oOO----(_)-------------------+
   |                Andrew Deren              |  
   |             aderen AT eecs DOT uic DOT edu          |
   | www.eecs.uic.edu/~aderen/ader/main.html  |
   +-------------------------oOO--------------+
                       || ||
                      ooO Ooo
 


On Wed, 28 Jan 1998, Chia wrote:

> I've got two classes...  Both of them have lots of constructive arguments,
> and I want to have one of them be contained from the other one.  Here's what
> I mean:
> 
> class a {
> public:
>  a(int b) {
>   x = b;
>  }
> protected:
>  int x;
> }
> 
> class b {
> public:
>  b(int x) {
>   // normally, I would just do this:
>   //  a class_a_instance(x);
>   // but that doesn't seem to work.
>   // any ideas on how to call class a's constructor
>   // if it's part of another class?
>   // thanks!  chia AT top DOT net
>  }
> protected:
>  a class_a_instance;
> }
> 

You can define class_a_instance a pointer to class a:
a *class_a_instance;

and then in the constructor just say:
class_a_instance = new a(some_int); 
> 

- Raw text -


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