c++ - Can C++0x still explicitly allocate with global operator new? -


:

One type can be impossible to assign with the operator :

Stretch non-disabled (zero) operator new (std :: size_t) = Delete; };

This type of object can only be assigned as a stack object or another type of member. It can not be heap-allocated directly without a non-portable trickery. (Since the user is the only way to call the constructor on allocated memory and the use of the above version is forbidden, the object can not be created properly.)

The removal of the operator is the new one to make it private in existing C ++, but it is clearly not being used by the global operator, which avoids class-specific lookup, still valid C ++ 0x?

  NonNewable * p = :: New NonNewable ();  

Did I leave nothing in the draft?


To be clear, it is valid C ++ 03 and:

  straight non-disabled [private: zero * operator new (std :: size_t) ); // not defined }; Int main () {// Ignore leaks, this is just an example zero * mem = operator new (size (NonOewable)); NonNewable * p =: new (memory) non-disabled (); P =: new non-disable (); Return 0; }   

I believe that you are right and Wikipedia is wrong. The C ++ 0x draft standard describes "Functions Deleted Works" (8.4p10) which can not be used in any way (or the program is bad). They do not play any part in looking for a different area or name than normal tasks. The relevant paragraphs related to new expressions are the same:

[5.3.4p8] A new expression receives the object by calling the allocation function (3.7.4.1). ...

[5.3.4p9] If the new expression starts with an unary :: operator, the name of the allocation function is seen in the global scope. Otherwise, if the allocated type is a square type T or array, then the function of the allocation is seen in the radius of T. If this lookup fails to find the name, or if the allotted type is not class type, the name of the allocation function is seen in the global scope.

Then yes, expression : new non-usable [or :: new (non-disabled) ] :: operator will select an overload of new , ignoring function NonNewable :: operator new , and the program will not be ill.


Comments