-2
template <class T>
class Matrix
{
private:
    T** data; // matrix elements stored here
    int rows; // number of rows
    int cols; // number of columns
public:
    Matrix(int numRows = 0, int numCols = 0); // makes storage allocation but leaves it uninitialized, for 0,0 dont allocate memory
    Matrix(T const* const* inputData, int numRows, int numCols);
    Matrix(const Matrix& rhs);
   ~Matrix();

I have to do implementation and normally I can. But this time I can't figure out what to do with T**

I am pretty newbie as you can see. At the first i thought as a double pointer but clearly it isn't. I can only use the ”iostream” header file and the Matrix class’ interface header file that which is given to me.

CgtyKy
  • 51
  • 10
  • What makes you say it isn't a double pointer? – psmears Mar 21 '15 at 20:27
  • Read [How do I use arrays in C++?](https://stackoverflow.com/questions/4810664/how-do-i-use-arrays-in-c). A lot of information about arrays and pointers. –  Mar 21 '15 at 20:30
  • `data` will be `nullptr` if the dimensions are 0, otherwise it will point at an array of pointers, each which point at an array of `T`. Probably you're expected to use `new` to allocate each of those arrays. – M.M Mar 21 '15 at 20:43

2 Answers2

0

Look in the following link, its pretty self-explanatory, and will guide your implementation (supposing you know how to do it without templates):

http://www.cplusplus.com/doc/tutorial/templates/#class_templates

You will end initializing your class as:

Matrix<int> *myMatrix = new Matrix<int>(data, 10,10);

or

Matrix<int> myMatrix(10,10);
lfn
  • 114
  • 1
  • 5
-1
Matrix::Matrix(int numRows = 0, int numCols = 0) 
    :data(new T[numRows][numCols]){}
Matrix::~Matrix(){delete [] data;} 

I'd let yourself figure out the rest.

user3528438
  • 2,737
  • 2
  • 23
  • 42