Wikipedia states:
A type can be made impossible to allocate with operator new:
struct NonNewable { void *operator new(std::size_t) = delete; };
An object of this type can only ever be allocated as a stack object or as a member of another type. It cannot be directly heap-allocated without non-portable trickery. (Since placement new is the only way to call a constructor on user-allocated memory and this use has been forbidden as above, the object cannot be properly constructed.)
Deleting operator new is similar to making it private in current C++, but isn't explicitly using global operator new, which avoids class-specific lookup, still valid C++0x?
NonNewable *p = ::new NonNewable();
// neither non-portable nor trickery, though perhaps not widely known
Have I missed something in the draft?
To be clear, this is valid C++03 and works fine:
struct NonNewable {
private:
void *operator new(std::size_t); // not defined
};
int main() {
// ignore the leaks, it's just an example
void *mem = operator new(sizeof(NonNewable));
NonNewable *p = ::new(mem) NonNewable();
p = ::new NonNewable();
return 0;
}