I want to have a stack-allocated array initialized by a copy constructor.
I only see methods allocating memory on the heap, or using std::array
.
With std::array
, it would look like the following:
class A
{
std::array<int, 5> my_array; // I would like to have int my_array[5]; instead of the std::array
int size;
public:
A(const A& p)
: my_array{ p.my_array }, size(p.size) {}
}
How can I implement this without std::array<int,5>
but with a plain array (int my_array[5];
)? I have added this in the comment in the code.
At the moment, the array contains integers. If this would contain, let's say a class B, which contains also a pointer:
class B
{
int* my_ptr;
}
Does std::array
handle this correctly and perform a deep copy?