Need help
I am new to the operators overloading , and now am trying to initialize a matrix by using operators [][] overloads. I would like to initialize the matrix using the following way : matrix [0][0] =100
is it possible to use [][] ? how do i use them ?
//main.cpp//
void main()
{
Matrix m(2, 2);
m[0][0] = 2;
}
//matrix.h//
#ifndef MATRIX_H
#define MATRIX_H
class Matrix
{
public :
Matrix(int ,int );
Matrix operator [][] // *****im stuck here*****
private :
int numRows;
int numCols;
int **matrix;
}
#endif
//matrix.cpp//
#include <iostream>
#include "Matrix.h"
using namespace std;
Matrix::Matrix(int rows,int cols)
:numOfCols(cols),numOfRows (rows)
{
matrix=new int *[cols];
for(int i=0;i<rows;i++)
{
matrix[i]=new int [cols];
for(int c=0;c<cols;c++)
{
matrix[i][c]=0;
}
}
}