
c++新特性学习笔记
锤%锤
这个作者很懒,什么都没留下…
展开
-
闭包的实现
方法一、仿函数#include "stdafx.h"#include <iostream>using namespace std;//仿函数,class myFunctor{public: myFunctor(int i):r(i){}//构造函数 //重载operator() int operator() (int tmp) { return tmp + r; }private: int r;};int main(){ myFunct原创 2022-03-31 17:43:03 · 314 阅读 · 0 评论 -
C++11新特性智能指针shared_ptr
C++11新特性智能指针1、shared_ptrshared_ptr允许多个指针共享同一堆分配的对象内存,通过引用计数(reference counting)实现。当最后一个指向该堆空间的指针被销毁后,堆空间就被释放了。#include "stdafx.h"#include <iostream>#include <memory>int main(){ shared_ptr<int> sp1(new int(11)); shared_ptr<原创 2022-03-31 11:20:46 · 964 阅读 · 0 评论