In the example below, I have a smart pointer sp
as a member variable and I want to assign a dynamically allocated array to it in the constructor, however I get a compiler error no match for ‘operator=’
, what is the correct way to do this?
In the example below, I have a smart pointer sp
as a member variable and I want to assign a dynamically allocated array to it in the constructor, is using the reset()
method of smart pointer the correct way to do this or should I be using a shared smart pointer?
struct SampleStructure
{
std::unique_ptr<idx_t[]> sp;
SampleStructure(int a, int b){
sp.reset(new idx_t[a + 1]);
}
};
Aucun commentaire:
Enregistrer un commentaire