c++ - 对 C++ 中范围解析运算符的困惑

标签 c++ templates

行中 :: 的作用: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 newoperator delete函数被调用,而不是那些可能已被该类覆盖的函数。

您可能会发现此函数是内存策略类的一部分,并从类'operator new 中调用。和 operator delete重写函数。

关于c++ - 对 C++ 中范围解析运算符的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41675239/

相关文章:

c++ - 万不得已/包罗万象/后备模板过载

c++ - 为什么c++中数组的内容有时没有初始化?

c++ - 有人可以帮助我处理 C++ 模板中的嵌套名称说明符吗?

templates - Angular 2 Dart 模板语法 : How to access static methods?

c++ - 什么是奇怪的重复模板模式(CRTP)?

c++ - 我的 C++ 代码中的错误在哪里?

c++ - 如何获取数组中值的索引

c++ - 光线追踪 : Only use single ray instead of both reflection & refraction rays

templates - 模板文本正文中不允许 JSF 和 EJB #{...}

c++ - 静态 constexpr 变量与函数