🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #695

new operator with multiple arguments (gcc-2.2.2)

#695
From: Jack V. Briner Jr.
Date: Fri, 22 Jan 1993 21:24
44 lines
1538 bytes
I would like to pass arguments to the new operator (to select memory from
different segments).  g++ does not seem to have this implemented under gcc-2.2.2.  Here is some example code that compiles fine under cfront.  Does a
newer release accept this code?

Thanks,
Jack


#include <iostream.h>
#include <stddef.h>
class t {
public:
        int i; 

        // ok
	void *operator new(size_t sz) {
             t *n;
             n = (t *)new char[sz];
             return n;
             }

        // not ok when used in main
	void *operator new(size_t sz,int i) {
             t *n;
             n = (t *)new char[sz];
             n->i = i;  // not what I am really doing in my application
             return n;
             }

};

main () {
   
   t *a = new t; // ok
   t *b = new(5) t; // not ok,  parse error before `5'
}
  


--
Jack V. Briner,Jr.		Department of Mathematics
brinerj@mcduff.uncg.edu		University of North Carolina at Greensboro
brinerj@steffi.uncg.edu		Greensboro, NC 27412
brinerj@UNCG.Bitnet		(919)334-5836
Technical Details
Message-ID: <22983@duke.cs.duke.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rock!concert!duke!mcduff.uncg.edu!brinerj

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rock!concert!duke!mcduff.uncg.edu!brinerj
From: brinerj@mcduff.uncg.edu (Jack V. Briner Jr.)
Newsgroups: gnu.g++.help
Subject: new operator with multiple arguments (gcc-2.2.2)
Message-ID: <22983@duke.cs.duke.edu>
Date: 22 Jan 93 21:24:50 GMT
Sender: news@duke.cs.duke.edu
Reply-To: brinerj@mcduff.uncg.edu (Jack V. Briner Jr.)
Organization: UNCG Department of Mathematics
Lines: 44
Nntp-Posting-Host: mcduff.uncg.edu