+ 8
How may I properly declare an object array using unique_ptr along with make_unique [ Solved ]
Hello coders, 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. I received the errors: errors recieved: 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]>; Altered and simplified sample code: https://code.sololearn.com/cT2O1JW3WH3p/#cpp
5 Respuestas
+ 4
According to the reference in https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
Construction for array type with known bound is not allowed. So I tried changing it to
std::unique_ptr<CrewMember[][3]> ship_crew_members = std::make_unique< CrewMember[][3]>(3);
And it works just fine
+ 4
Solved coded https://code.sololearn.com/cpzfvDFQJg5I/#cpp
+ 2
Alright, I filtered out all the unnessary code, then linked the code to the description.
+ 2
~ swim ~
Thank you!😄
+ 1
Thank you very much Agent_I !