[英]confusion about scope resolution operator in c++
:: 在线做什么: 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);
}
};
像这样使用范围解析运算符::
意味着调用全局operator new
和operator delete
函数,而不是可能已为该类覆盖的函数。
您可能会发现该函数是内存策略类的一部分,并从类的operator new
和operator delete
重写函数调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.