Path: utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!SPERM.OCEAN.WASHINGTON.EDU!keffer From: keffer@SPERM.OCEAN.WASHINGTON.EDU (Tom Keffer) Newsgroups: gnu.g++.bug Subject: Variable sized objects Message-ID: <8911102130.AA22272@sperm.ocean.washington.edu> Date: 10 Nov 89 21:30:19 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 55 Michael, I am trying to figure out how to use g++ to make objects of variable size. This may reflect a misunderstanding on my part about how overloaded new with extra arguments is supposed to work (no clues in Lippman about this). As always, Sun 3/260, SunOS 3.5. g++ 1.36.1 w. libg++ 1.36.1 --- Dr. Thomas Keffer | Internet: keffer@ocean.washington.edu Rogue Wave Assoc. | BITNET: keffer%ocean.washington.edu@UWAVM Seattle, WA 98145 | uucp: uw-beaver!ocean.washington.edu!keffer (206) 523-5831 | Telemail: T.KEFFER/OMNET #include class Vector { int nelem; //Number of elements int array[1]; //Placeholder for beginning of data space public: // Allocate enuf space for a Vector of length "n" off the heap. // Is this syntax correct? void* operator new(long size, int n); Vector(int n) {nelem = n;} }; main() { // Should make a vector capable of holding 44 elements. I think. Vector *a = new (44) Vector(44); } void* Vector::operator new(long size, int n) { void* hold = malloc(size + (n-1)*sizeof(int)); return hold; } Results: g++ -v junk.cc gcc version 1.36.1 (based on GCC 1.36) /usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 junk.cc /usr/tmp/cca22262.cpp GNU CPP version 1.36 /usr/local/lib/gcc-cc1plus /usr/tmp/cca22262.cpp -quiet -dumpbase junk.cc -version -o /usr/tmp/cca22262.s GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36. default target switches: -m68020 -mc68020 -m68881 -mbitfield junk.cc: In method Vector::Vector (int): junk.cc:10: too few arguments for method `operator new' junk.cc: In function int main (): junk.cc:16: parse error before `44' Compilation exited abnormally with code 1 at Fri Nov 10 13:27:07