Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: It doesn't like 'super' where ever I put it. Date: Sun, 10 Jun 2012 11:38:39 -0600 Organization: inverse squares and the quintesimal radicals Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="dZdavj/jUDynNQgDq5jkeA"; logging-data="32274"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y2WxcuCEZbGWOcBwXqWqw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:TlRnWDdPMYxKXasrLoP3h6PjyD8= sha1:6CJn+Zw+XrcAvVnE4wIEGK3DT8E= Xref: csiph.com comp.lang.java.programmer:15182 ram@zedat.fu-berlin.de (Stefan Ram) writes: > Jim Janney writes: >>want to run whenever a new object is created, and it would be tedious to >>have to call it explicitly every time. I used to mimic OOP in C and you >>had to do things like >>struct Foo* foo = (struct Foo*) malloc(sizeof(struct Foo)); >>foo->init(); > > When you find that you happen to write certain code parts > repeatedly, you can write a function in C: > > struct alpha * new_alpha() > { struct alpha * const alpha = malloc( sizeof *alpha ); > if( alpha )alpha->init(); return alpha; } > > . This also is more safe, because it uses »alpha« only if > it is nonzero. Yes, and this is a good idea. I was trying to explain the distinction between allocating memory for an object and actually initializing it, and I couldn't think of a way to do that without referring to a language that lets you separate them. -- Jim Janney