摘要:operator new 的功能很简单, 就是分配一块连续的内存。 当我们写下::operator new时, 调用的实际上就是全局的operator new。 new operator 的功能就会复杂一些。 如果内存分配失败, 上述代码并不会返回一个空指针, 而是会抛出一个异常。 当我们写下上述代
阅读全文
摘要:#include using namespace std; pair a[100005], tmp[100005]; double ans; double getDis(const pair& lhs, const pair& rhs) { return (lhs.first-rhs.first)*(lhs.first-rhs.first) + (lhs.second-rhs.se...
阅读全文
摘要:template class shared_ptr { public: explicit shared_ptr (T *ptr): mPtr(ptr), cnt(new int(1)){} shared_ptr(const shared_ptr& rhs): mPtr(rhs.mPtr), cnt(rhs.cnt){ ++*cnt; } shared_ptr& oper...
阅读全文