Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nnews!zaphod.mps.ohio-state.edu!ncar!ncar.ucar.edu!vanandel From: vanandel@ncar.ucar.edu (Joe Van Andel) Newsgroups: comp.lang.c++ Subject: arguments to constructors for arrays of objects Keywords: constructors arrays Message-ID: <11338@ncar.ucar.edu> Date: 8 May 91 21:52:04 GMT Sender: news@ncar.ucar.edu Reply-To: vanandel@ncar.atd.ucar.edu (Joe Van Andel) Organization: National Center for Atmospheric Research Lines: 35 Forgive me if this has been discussed recently, but I need to know what (if any) is the syntax for allocating an array of objects, and calling a constructor with arguments for each: If I have a constructor defined with no arguments for the class, I can say: FAST WSmeBSB *eptr = new WSmeBSB[count]; I've tried: FAST WSmeBSB *eptr = new WSmeBSB[count](arg1, arg2); and FAST WSmeBSB *eptr = new WSmeBSB (arg1, arg2)[count]; My compiler won't accept either. I'm using the WWL-1.2 package, and I'm trying to allocate an array of Athena Simple Menu Entries, if you are curious. I'm using g++ version 1.39.0 beta (based on GCC 1.39), on a Sun3, running 4.1.1 A related question, is it safe to allocate space for an array of objects yourself, e.g.: FAST WSmeBSB *eptr = (WSmeBSB *)XtMalloc(sizeof(WSmeBSB) * count); Each of these objects in the dynamic array is later explicitly assigned to. Please email me your responses, and I'll summarize. Joseph VanAndel Internet:vanandel@ncar.ucar.edu NCAR Mail Stop MAR P.O Box 3000 Fax: 303-497-2044 Boulder, CO 80307-3000 Voice: 303-497-2071