Date: Thu, 29 Jan 1998 04:19:23 -0500 (EST) Message-Id: <199801290919.EAA18880@p2.acadia.net> To: "Chia" Subject: Re: Easy C++ stuff... I hope, anyway. Cc: djgpp AT delorie DOT com References: <6aolmn$3vs AT nnrp3 DOT farm DOT idt DOT net> in-reply-to: <6aolmn$3vs@nnrp3.farm.idt.net> From: swarnerx3 AT acadia DOT net (Scott Warner) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Precedence: bulk In message <6aolmn$3vs AT nnrp3 DOT farm DOT idt DOT net>, "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; > } > Something like class a { public: a(int b) { x=b; } private: int b; }; class b { public: b(int x) { pa = new a(x); } private: a* pa; }; is an example of containment where your data member class in b (pa) is a pointer that is defined in the constructor of b... you could also try multiple inheritance, but this is a completely different route that I wouldn't recommend if containment is possible.