I wrote some code that produces this:
The code producing such errors is:Code:1>c:\users\comp sci\documents\visual studio 2010\projects\predatorpreysimulation\predatorpreysimulation\world.h(25): error C2665: 'std::vector<_Ty>::vector' : none of the 7 overloads could convert all the argument types 1> with 1> [ 1> _Ty=World::UniqueOrganism 1> ] 1> c:\microsoft visual studio 10.0\vc\include\vector(521): could be 'std::vector<_Ty>::vector(unsigned int,const _Ty &)' 1> with 1> [ 1> _Ty=World::UniqueOrganism 1> ] 1> while trying to match the argument list '(int, nullptr)' 1> 1>Build FAILED.
I know there is no copy/assign with unique_ptr. There is also no copy constructor with unique_ptr and that unique_ptr owns the object without reference counting. What is lacking in my understanding?Code:class World{ struct UniqueOrganism{ std::unique_ptr<Organism> unique_organism; UniqueOrganism() {} // Move constructor UniqueOrganism(UniqueOrganism &object){ unique_organism = std::move(object.unique_organism); } }; std::vector<std::vector<UniqueOrganism>> cell_grid; public: World() { cell_grid = std::vector<std::vector<UniqueOrganism>> (20, std::vector<UniqueOrganism>(20, nullptr)); } ~World() {} };
What I am uncertain of is unique_ptr can reside within a container. Because copy/assign is not supported, I chose to embed the unique_ptr inside a class



LinkBack URL
About LinkBacks



CornedBee