简体   繁体   中英

'operator new' : function does not take 2 arguments

I cannot seem to get my placement new to work for some reason. Based on this question, I have set this up correctly .

However, I continue to get the error:

'operator new' : function does not take 2 arguments

Here is my code:

char * p = new char [sizeof(Node) * 5];
Node* node = new(p) Node();

where Node is a linked list node. I have tried to simplify this down based on the other stack overflow question, and I am still getting the same error:

char *buf  = new char[sizeof(int)]; // pre-allocated buffer
int *p = new (buf) int;

Does anyone know why I am having this issue?

Any help is greatly appreciated!

PS, this works:

Node* node = new Node();

Most likely, you didn't include <new> . You need that for the declarations of the standard forms of placement-new.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM