首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用“使用std::unique_ptr<T>::unique_ptr`”在Visual 2013中生成错误

使用“使用std::unique_ptr<T>::unique_ptr`”在Visual 2013中生成错误
EN

Stack Overflow用户
提问于 2020-03-26 09:56:38
回答 1查看 85关注 0票数 0

我正在尝试更新一些源代码,使其与Visual 2013兼容。

在某种程度上,下面的模板出现了错误:

代码语言:javascript
复制
// 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(); }
};

我得到以下错误:

代码语言:javascript
复制
error C2886: 'unique_ptr<_Ty,std::default_delete<_Ty>>' : symbol cannot be used in a member using-declaration

我想知道如何修改这些代码,使其与Visual 2013兼容,以及代码的含义。如何更新它以使代码与VS2013兼容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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构造函数的构造函数(这将使类更加详细),例如:

代码语言:javascript
复制
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(); }
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60864675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档