I am writing own 2d matrix class. I want to design the use of this class much close to real math notation. For example I want access to element as matrix[3, 6]. But c++ didn`t give this ability, but I could access to base multidimensional array in the next way:
int matrix[2][2] = {};
int val = matrix[1][0];
So I decided to make function that return the base array. For this role the best function will be operator(). So I can access in next way: matrix()[1][0]. Ok, I started to implement it and stuck :(. Look what I have:
template <typename ValType>
class Matrix2D
{
protected:
ValType m_data[2][2] = {};
public:
ValType** operator()() // <--- what type?
{
return m_data;
}
}
But I received compiler error in function above
error C2440: 'return' : cannot convert from 'double [2][2]' to 'double **'
I understand error but no have idea what I must change to avoid this error? What type the function must to return?
Aucun commentaire:
Enregistrer un commentaire