4 ms·
So basically you would like to be able to write this: struct Bar { int * one; int * two; int * three; Bar() {
by detrino 13y ago
So basically you would like to be able to write this:
struct Bar
{
int * one;
int * two;
int * three;
Bar()
{
one = new int{1};
two = new int{2};
three = new int{3};
}
~Bar()
{
if (!one) return;
delete one;
if (!two) return;
delete two;
if (!three) return;
delete three;
}
};
and that is somehow cleaner and more efficient than this:
struct Bar
{
std::unique_ptr<int> one;
std::unique_ptr<int> two;
std::unique_ptr<int> three;
Bar()
:
one{new int{1}},
two{new int{2}},
three{new int{3}}
{}
};