我无法理解为什么一个模板实例化在我的代码中有效,而另一个却不能。
我正在使用我创建的类模板:
template <typename T>
struct Allocated {
public:
const T& get() const& {
return *ptr.get();
}
T& get() & {
return *ptr.get();
}
T&& get() && {
return std::move(*ptr.get());
}
operator T& () & {
return *ptr.get();
}
operator const T& () const & {
return *ptr.get();
}
operator const T () && {
return std::move(* ptr.get());
}
template <typename U>
Allocated(const U& u) : ptr(std::make_unique<T>(u)) {}
template <typename U>
Allocated(U&& u) : ptr(std::make_unique<T>(std::move(u))) {}
Allocated() = delete;
Allocated(const …Run Code Online (Sandbox Code Playgroud)