I'm implementing tabu search algorithm in Visual Studio 2013.
I would like to have a function that generates neighbourhood (it is an std::array
of std::unique_ptr
's to the objects of class Neighbour
).
Unfortunately, i can't move std::array
of unique pointers (I can move std::unique_ptr<Neighbour>
).
I've checked that std::unique_ptr<Neighbour>
must be moveable - so it is.
#include <iostream>
#include <memory>
#include <array>
class Neighbour {
public:
virtual ~Neighbour(){};
};
class Neighbourhood
{
public:
using Neighbours = std::array<std::unique_ptr<Neighbour>, 12>;
protected:
Neighbours neighbourhood;
unsigned size;
};
int main()
{
Neighbourhood::Neighbours n1;
Neighbourhood::Neighbours n2;
n2 = std::move(n1);
}
On Coliru it is working: http://ift.tt/1ZIQNdq I suppose that something is wrong with implementation of C++11 in Visual Studio 2013.
Do you know how can I fix it?
And the error is:
1>------Build started : Project : Project5, Configuration : Debug Win32------
1> Source.cpp
1>c:\users\radek\documents\visual studio 2013\projects\project5\project5\source.cpp(29) : error C2280 : 'std::unique_ptr<Neighbour,std::default_delete<_Ty>> &std::unique_ptr<_Ty,std::default_delete<_Ty>>::operator =(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function
1> with
1>[
1> _Ty = Neighbour
1>]
1> c:\program files(x86)\microsoft visual studio 12.0\vc\include\memory(1487) : see declaration of 'std::unique_ptr<Neighbour,std::default_delete<_Ty>>::operator ='
1> with
1>[
1> _Ty = Neighbour
1>]
1> This diagnostic occurred in the compiler generated function 'std::array<std::unique_ptr<Neighbour,std::default_delete<_Ty>>,12> &std::array<std::unique_ptr<_Ty,std::default_delete<_Ty>>,12>::operator =(const std::array<std::unique_ptr<_Ty,std::default_delete<_Ty>>,12> &)'
1> with
1>[
1> _Ty = Neighbour
1>]
== == == == == Build: 0 succeeded, 1 failed, 0 up - to - date, 0 skipped == == == == ==
Aucun commentaire:
Enregistrer un commentaire