Date: Thu, 29 Jan 1998 19:20:13 -0600 (CST) From: Andrew Deren To: Chia 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk ,,, (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); >