I created a simple matrix definition like so:
template <size_t m, size_t n>
using Matrix = boost::array<boost::array<float, n>, m>;
I wish to overload the [] operator so that I can access the matrix values with matrix[i, j]
instead of matrix[i][j]
. I tried the following but to no avail.
template <size_t m, size_t n>
float& Matrix<m,n>::operator[](uint32_t i, uint32_t j) {
return &(this[i][j]);
I could not make sense of partial template specialization, and generally do not understand why I can't overload the operator.
clang++ 10.0.1 compile output is
matri.cpp:10:21: error: nested name specifier 'Matrix<m, n>::' for declaration does not refer into a class, class template
or class template partial specialization
float& Matrix<m,n>::operator[](uint32_t i, uint32_t j) {
~~~~~~~~~~~~~^
matri.cpp:11:14: error: invalid use of 'this' outside of a non-static member function
return &(this[i][j]);
^
matri.cpp:11:19: error: use of undeclared identifier 'i'
return &(this[i][j]);
^
matri.cpp:11:22: error: use of undeclared identifier 'j'
return &(this[i][j]);