我正在尝试更新一些源代码,使其与Visual 2013兼容。
在某种程度上,下面的模板出现了错误:
// Means of generating a key for searching STL collections of std::unique_ptr
// that avoids the side effect of deleting the pointer.
template <class T>
class FakeUniquePtr : public std::unique_ptr<T> {
public:
using std::unique_ptr<T>::unique_ptr;
~FakeUniquePtr() { std::unique_ptr<T>::release(); }
};我得到以下错误:
error C2886: 'unique_ptr<_Ty,std::default_delete<_Ty>>' : symbol cannot be used in a member using-declaration我想知道如何修改这些代码,使其与Visual 2013兼容,以及代码的含义。如何更新它以使代码与VS2013兼容?
发布于 2020-03-26 10:51:56
根据这篇微软博客文章:https://devblogs.microsoft.com/cppblog/c1114-core-language-features-in-vs-2013-and-the-nov-2013-ctp/这个被称为“继承构造函数”的特性在Visual 2013的常规版本中是不可用的(本文提到了2013年11月的CTP构建,它确实支持它)
如果没有此特性,您将不得不编写调用等效std::unique_ptr构造函数的构造函数(这将使类更加详细),例如:
template <class T>
class FakeUniquePtr : public std::unique_ptr<T> {
private:
// typedef to minimize writing std::unique_ptr<T>
typedef std::unique_ptr<T> base;
public:
FakeUniquePtr() : base(){}
// repeat for all other constructors
~FakeUniquePtr() { base::release(); }
};https://stackoverflow.com/questions/60864675
复制相似问题