Jepessen
Jepessen

Reputation: 12415

Build error in Visual Studio 2013 with `using std::unique_ptr<T>::unique_ptr`

I'm trying to update some source code for making it compatible with Visual Studio 2013.

At some point I've an error on following template:

// 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(); }
};

I obtain the following error:

error C2886: 'unique_ptr<_Ty,std::default_delete<_Ty>>' : symbol cannot be used in a member using-declaration

I'd like to know how can I adapt this code to make it compatible with Visual Studio 2013, and what's the meaning of that code. How can I update it for making code compatible with VS2013?

Upvotes: 0

Views: 171

Answers (1)

UnholySheep
UnholySheep

Reputation: 4096

According to this Microsoft blog article: https://devblogs.microsoft.com/cppblog/c1114-core-language-features-in-vs-2013-and-the-nov-2013-ctp/ this feature, known as "inheriting constructors", is not available in the regular version of Visual Studio 2013 (the article mentions the Nov 2013 CTP build, which does support it)
Without this feature you will have to write constructors that call the equivalent std::unique_ptr constructors (which will make the class a lot more verbose), e.g.:

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(); }
};

Upvotes: 1

Related Questions