Path: utzoo!attcan!uunet!mcvax!ukc!strath-cs!glasgow!orr From: orr@cs.glasgow.ac.uk (Fraser Orr) Newsgroups: comp.lang.c++ Subject: A very simple question. Message-ID: <1606@crete.cs.glasgow.ac.uk> Date: 2 Sep 88 16:22:07 GMT Reply-To: orr%cs.glasgow.ac.uk@nss.ucl.ac.uk (Fraser Orr) Organization: Comp Sci, Glasgow Univ, Scotland Lines: 43 There is probably a very simple answer to this question, unfortunately I don't know it! I'm trying to create an object with, as some of it's private data members, other objects. Now these data members are objects with constructors, as is the object containing it. Unfortunately this doesn't seem to be allowed (data members may not have constructors). As an example ... class a { int b ; public: a ( int c) { b=c ; } ; } ; class d { a NeedsCtor (1) ; // This line is illegal public: d (int e ) { ... } ; } ; Is it necessary to have a constructor with no parameters for every object that may be used as a data member? I know that it is also possible to have a pointer to a as the data member, and then do a new in d's constructor, but I thought we had got away from all that tacky stuff when we moved to C++. I'm probably missing something obvious, so I would appreciate any enlightenment. Thanks, ==Fraser Orr ( Dept C.S., Univ. Glasgow, Glasgow, G12 8QQ, UK) UseNet: {uk}!cs.glasgow.ac.uk!orr JANET: orr@uk.ac.glasgow.cs ARPANet(preferred xAtlantic): orr%cs.glasgow.ac.uk@nss.cs.ucl.ac.uk