这个构造函数为何用不了了呢?
```c++
#include <memory>
#include <iostream>
using namespace std;
void MyDeleter(shared_ptr<int> p) {}
int main() {
shared_ptr<int> pi = make_shared<int>(42);
shared_ptr<int> pt(pi, MyDeleter);
return 0;
}
```
这个构造函数为何用不了了呢?
```c++
#include <memory>
#include <iostream>
using namespace std;
void MyDeleter(shared_ptr<int> p) {}
int main() {
shared_ptr<int> pi = make_shared<int>(42);
shared_ptr<int> pt(pi, MyDeleter);
return 0;
}
```
目前c++没有这个构造函数,可能是老版本的
constexpr shared_ptr() noexcept;
(1)
constexpr shared_ptr( std::nullptr_t ) noexcept;
(2)
template< class Y >
explicit shared_ptr( Y* ptr );
(3)
template< class Y, class Deleter >
shared_ptr( Y* ptr, Deleter d );
(4)
template< class Deleter >
shared_ptr( std::nullptr_t ptr, Deleter d );
(5)
template< class Y, class Deleter, class Alloc >
shared_ptr( Y* ptr, Deleter d, Alloc alloc );
(6)
template< class Deleter, class Alloc >
shared_ptr( std::nullptr_t ptr, Deleter d, Alloc alloc );
(7)
template< class Y >
shared_ptr( const shared_ptr& r, element_type* ptr ) noexcept;
(8)
template< class Y >
shared_ptr( shared_ptr&& r, element_type* ptr ) noexcept;
(8) (C++20 起)
shared_ptr( const shared_ptr& r ) noexcept;
(9)
template< class Y >
shared_ptr( const shared_ptr& r ) noexcept;
(9)
shared_ptr( shared_ptr&& r ) noexcept;
(10)
template< class Y >
shared_ptr( shared_ptr&& r ) noexcept;
(10)
template< class Y >
explicit shared_ptr( const std::weak_ptr& r );
(11)
template< class Y >
shared_ptr( std::auto_ptr&& r );
(12) (C++17 中移除)
template< class Y, class Deleter >
shared_ptr( std::unique_ptr<Y,Deleter>&& r );
(13)