Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!fuug!fuug.fi!pena From: pena@brainware.fi (Olli-Matti Penttinen) Newsgroups: comp.lang.c++ Subject: Re: Constructor Limitation: [Was: Re: Constructor question] Message-ID: Date: 3 Jun 91 08:49:28 GMT References: <1389@appli.se> Sender: usenet@fuug.fi (USENET News System) Followup-To: comp.lang.c++ Organization: Brainware Oy, Espoo, Finland. Lines: 66 In-Reply-To: niklas@appli.se's message of 2 Jun 91 01: 33:01 GMT Nntp-Posting-Host: brainw.brainware.fi In article <1389@appli.se> niklas@appli.se (Niklas Hallqvist) writes: I wrote :Besides, Bjarne's proposal to use a protected init-method works well, :too, iff A has a default constructor. Admittedly, things might get a :little dirty if an A cannot have a meaningful state constructed out of :nothing. In that case, one could (accidentally) use the value of an A :before the object is fully constructed, so the problem would still be :there. :All in all, I don't see a reason to extend the language just because :a new feature would occasionally save a few keystrokes. : [ more text deleted ] Niklas You forgot to read the requirements of the problem. The class A and the function f could not be altered (probably due to a binary only license of some library). The way to do this is of course by using MI, private inheritance and the well-known dependence of base class declaration order ;-) class A { public: A(int a, int b, int c, int d); // ... }; void f(const char* s, int* a, int* b, int* c, int* d); class B_helper { protected: int a, b, c, d; B_helper(const char* s) { f(s, &a, &b &c, &d); } }; class B : private B_helper, public A { public: B(const char* s) : B_helper(s), A(a, b, c, d) { /* usual code */ } // ... }; -- Niklas Hallqvist Phone: +46-(0)31-40 75 00 Applitron Datasystem Fax: +46-(0)31-83 39 50 Molndalsvagen 95 Email: niklas@appli.se S-412 63 GOTEBORG, Sweden mcsun!sunic!chalmers!appli!niklas Well, I wasn't aware of that A couldn't be altered. And I'm sorry I stated my case poorly. My real objective was to show that whoever wrote A in the first place, should have allowed for A::A() and a protected init-method, which could be used by A's children to constrct an A form any set of values whatsoever. I still don't agree with the proposition to extend the language because of existing poor programming practices. Your solution probably works (I haven't tested it either), but as you said yourself, it is a horrible kludge only very few programmers understand, let alone be able to use themselves. ==pena -- Olli-Matti Penttinen | "When in doubt, use brute force." Brainware Oy | --Ken Thompson P.O.Box 330 +---------------------------------- 02151 ESPOO, Finland Tel. +358 0 4354 2565 Fax. +358 0 461 617