Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
'
new': cannot allocate 'void' objects
Remarks
The new operator allocates memory and constructs an object of the specified type. Since void isn't a constructible type, use ::operator new(size) to allocate raw memory without object construction.
Example: Wrong allocation type
// compile with /c
int main()
{
void* ptr1 = new void; // C2469
int* ptr2 = new int; // OK
}
Example: Allocate untyped memory
To allocate untyped memory, use ::operator new:
// compile with /c
int main()
{
void* ptr1 = new void; // C2469
void* ptr2 = ::operator new(4); // OK
}