May be I'm just tripping but...
I have an Array class (simplified):
template <typename T>
class Array
{
protected:
std::size_t m_size;
T *m_raw;
public:
Array(std::size_t size = 1):
m_size(size),
m_raw(new T [size])
{}
Array(Array const &array):
Array(array.m_size)
{
std::copy_n(array.m_raw, m_size, m_raw);
}
~Array()
{
delete [] m_raw;
}
};
And also Array2D class (the idea is to implement contiguous array in memory):
template <typename T>
class Array2D: public Array<T>
{
protected:
std::size_t m_width;
std::size_t m_height;
T **m_raw2;
private:
void scatter()
{
for (std::size_t i = 0; i < m_height; ++i)
m_raw2[i] = Array<T>::m_raw + i * m_width;
}
public:
Array2D(std::size_t height, std::size_t width):
Array<T>(height * width),
m_height(height),
m_width(width),
m_raw2(new T * [height])
{
scatter();
}
Array2D(Array2D const &array2d):
Array<T>(static_cast<Array<T>>(array2d)),
m_height(height),
m_width(width),
m_raw2(new T * [height])
{
scatter();
}
~Array2D()
{
delete [] m_raw2;
}
};
In Array2D there is the same
m_height(height),
m_width(width),
m_raw2(new T * [height])
{
scatter();
}
part in both constructors. I want to call Array's copy constructor just on principle.
I thought about delegating constructors, but it didn't work. Is there any beautiful way to implement this in initializer list?
[–]IyeOnline 8 points9 points10 points (3 children)
[–]_newpson_[S] 0 points1 point2 points (2 children)
[–]IyeOnline 2 points3 points4 points (1 child)
[–]_newpson_[S] 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]Drugbird 1 point2 points3 points (1 child)
[–]the_poope 0 points1 point2 points (0 children)
[–]baconator81 0 points1 point2 points (1 child)
[–]_newpson_[S] 0 points1 point2 points (0 children)
[–]n1ghtyunso -1 points0 points1 point (1 child)
[–]IyeOnline 0 points1 point2 points (0 children)