行中 :: 的作用:return::operator new(size,::std::nothrow); 以及为什么类在没有使用模板类型 T 时使用模板
template<typename T>
class DefaultMemoryAllocator
{
public:
static inline void *Allocate(size_t size)
{
return ::operator new(size, ::std::nothrow);
}
static inline void Deallocate(void *pointer, size_t size)
{
::operator delete(pointer);
}
};
最佳答案
使用范围解析运算符 ::
像这样意味着 global operator new
和 operator delete
函数被调用,而不是那些可能已被该类覆盖的函数。
您可能会发现此函数是内存策略类的一部分,并从类'operator new
中调用。和 operator delete
重写函数。
关于c++ - 对 C++ 中范围解析运算符的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41675239/