Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!bonnie.ics.uci.edu!schmidt From: schmidt@bonnie.ics.uci.edu (Douglas C. Schmidt) Newsgroups: comp.lang.c++ Subject: use of new allocator with reference variables Keywords: c++, new, reference Message-ID: <646@paris.ICS.UCI.EDU> Date: 25 Aug 88 22:29:37 GMT Sender: news@paris.ics.uci.edu Reply-To: schmidt@bonnie.ics.uci.edu (Douglas C. Schmidt) Distribution: na Organization: University of California, Irvine - Dept. of ICS Lines: 29 References: Hi, I've been browsing through Stroustrup's C++ book and came across the following puzzling construct on page 34: Vec& sum = *new Vec(s); I don't believe that this use of the new allocator (preceded by the '*') is described anywhere else in the book. Could someone please explain the meaning of this, in the context of the function depicted below? Vec operator+(Vec a, Vec b) { int s = a.size(); if (s != b.size()) error("foo"); Vec& sum = *new Vec(s); int *sp = sum.v; int *ap = a.v; int *bp = b.v; while (s--) *sp++ = *ap++ + *bp++; return sum; } thanks! Doug Schmidt -- schmidt@bonnie.ics.uci.edu (ARPA) "If our behavior is strict, we do not need fun." -Zippy th' Pinhead "If our behavior is struct, we do not need defun." -Anon