【发布时间】:2019-02-22 11:58:54
【问题描述】:
我有以下课程:
struct pool : public std::enable_shared_from_this<pool> {
private:
struct manager {
explicit manager(const std::weak_ptr<pool> &pool) : m_pool{pool} {
}
explicit manager() = default;
auto operator()(connection *conn) -> void;
private:
std::weak_ptr<pool> m_pool;
};
public:
pool(const pool &) = delete;
auto operator=(const pool &) -> pool & = delete;
auto borrow() noexcept -> std::unique_ptr<connection, manager>;
}
其中connection 与pool 具有相同的可见性。
在我的测试中,我可以将 borrow() 与 auto 一起使用:
auto p = std::make_shared<pool>();
auto conn = p->borrow();
但是我不能声明一个与borrow()的返回类型相同类型的变量:
std::unique_ptr<connection, manager> conn;
clang 返回错误:
error: 'manager' is a private member of 'dbc::detail::pool'
这两者不应该互换吗?
【问题讨论】: