I am trying to declare and initialize a unique_ptr holding a class array
This is a sample I am using to solve a memory management issue with my project. I can declare the pointer but I am not able to initialize it.
class CrewMember
{
};
class SpaceShip
{
// generates error
std::unique_ptr<CrewMember[3][3]> ship_crew_members = std::make_unique< new CrewMember[3][3]>;
// compiles fine
std::unique_ptr<CrewMember[3][3]> ship_crew_members;
};
errors received:
call to non-constexpr function 'void* operator new ' std::unique_ptr ship_crew_members = std::make_unique< new CrewMember[3][3]>;
^
cannot resolve overloaded function 'make_unique' based on conversion to type 'std::unique_ptr' std::unique_ptr ship_crew_members = std::make_unique< new CrewMember[3][3]>;
make_uniqueis a function template. You need to domake_unique<Type>().std::make_unique< new CrewMember[3][3]>90% sure you can't usenewin this context.std::make_unique<CrewMember[3][3]>(), though I'm not sure this is completely correct.cpp std::unique_ptr<CrewMember[3][3]> ship_crew_members = std::make_unique< CrewMember[3][3]>();recieved pastebin.com/Kma1Q4S8