From: G DOT DegliEsposti AT ads DOT it To: djgpp AT delorie DOT com Message-ID: Date: Thu, 29 Jan 1998 09:54:09 +0100 Subject: Re: Easy C++ stuff... I hope, anyway. Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk >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 This is not djgpp specific, it was better posting to comp.lang.c++... anyway... >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; >} if you declare a member of class "a" you must provide a default constructor for that class (i.e. a constructor without arguments). you can try one of these: 1) class b : public a { b(int x) : a(x) { ... 2) a *class_a_instance; b(int x) { class_a_instance = new a(x); ... of course c++ allows other MAXINT more solutions, but two is a beginning :-) ciao Giacomo