I'm writing a matrix class for CUDA processing.
I've written a vector class (henceforth known as Elements
) and used that for the matrix base.
Here is the template definition:
template <typename T, std::size_t M, std::size_t N>
class Matrix : public Elements< Elements< T, N >, M > {
}
It should be noted that nothing is dynamically allocated in the Elements
class, nor in the Matrix
class.
I'm getting a warning: base class ‘struct Elements<Elements<double, 2ul>, 2ul>’ should be explicitly initialized in the copy constructor
warning in the copy constructor. Here is the copy constructor:
DEVICE HOST
Matrix(const Matrix & that) {
for (std::size_t ind = 0; ind < M; ind++) {
for (std::size_t jnd = 0; jnd < N; jnd++) {
(*this)[ind][jnd] = that[ind][jnd];
}
}
}
What am I doing wrong?
You're not initializing the base class in the copy constructor. Try this:
Matrix(const Matrix & that) : Elements<Elements<T, N>, M>(that) {
/* ... */
}
The initializer list of the derived class' copy constructor should contain an explicit call to the base class' copy constructor, just like with all other constructors, otherwise, the base class will be default-initialized.
Edit: It can be handy to have a private
typedef Elements<Elements<T, N>, M> basetype;
in your class definition somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With