In the past few days, anglescript has a new understanding of C ++. For example, placement new
This is actually a global new operator that cannot be overwritten. It is used to reconstruct existing objects. Re-build, rather than re-allocate, so it can only work on the allocated memory space. This is exactly the meaning of "placement ".
For exampleInt* P =New int[5];
New(P)Int[5];
This is legal.
WhileInt* P;
New(P)Int[5]; // an error occurs during the execution period. Because p is not allocated beforehand.
In fact, placement new is to re-call the object's constructor.
The younger brother was a beginner and just learned about this operator in recent days. He first saw some anglescript simple operators on the Internet to construct objects. I didn't understand what it meant at the beginning. I just copied it to my project. However, it was not possible to pass the compilation, and I didn't care at the time. I thought it was an action to create an object from heap, So I replaced it with P = new OBJ. But it will soon be reflected. This will not work, because P points to a reallocated space in this statement. Script has allocated space for P, but it is re-constructed with new parameters.
But why can't I find the answer after Google's compilation. Therefore, a common console is created.Program. The compilation of the same statement does not seem to be a problem with the compiler. Compared with the compiler options of two projects, there is no essential difference. Strange.
The <New> header file contains a Conditional compilation.
# Ifndef _ Placement_new_inline
Didn't I define it?
After definition, the afxtempl. h compilation error is prompted.
Locate the error and the answer will be discovered.
# Pragma push_macro("New ")
# UNDEF new
::New((Void*) (& Pnode-> data) type;
# Pragma pop_macro("New ")
Damn it, they don't want to tell me, too harsh.
Return to <New> and find the two definitions at the bottom of the file.
# Ifdef _ msc_ver
# Pragma pop_macro("New ")
nnd, killed by them. But it is actually usable. Share it with you. You may encounter similar problems one day.