Where do std::bind-created functors live?

▼魔方 西西 提交于 2019-12-01 16:54:51

std::bind returns an object by value (the object's exact type is an implementation detail of the standard library). This object stores all necessary state and its destructor does all the required cleanup.

Notice that your vector does not store pointers - it stores std::function objects. A std::function object internally stores the object from which it was created (a function pointer or the object returned by std::bind in your case), and its destructor correctly destroys the stored object. Destroying a pointer to function does nothing. Destroying an object of class type invokes its destructor.

The std::bind function creates an instance of an unspecified class, and when that object goes out of scope and is destructed, so is the storage for that instance.

Just like instances of any other class with a destructor that releases some resource.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!