I'm attempting to make a matrix class, and so far I've made a member that can make a vector of vectors, but I'm not sure how to go about resizing the vectors if need be.
EX: resizeArray(3,3) should return a 3x3 vector.
Also, for some reason when I call my default member, matrix(), I get an error that says... "Request for member numrows in myMatrix, which is of type matrix[][]" I'm not entirely sure what that's asking for and couldn't find a suitable answer elsewhere.
Thanks in advance
#include <iostream>
#include <vector>
using namespace std;
template <typename Object>
class matrix
{
public:
matrix( ) : array( 1 )
{
rows = 1;
cols = 1;
for( int i = 0; i < rows; i++ )
array[ i ].resize( cols );
}
matrix( int rows, int cols ) : array( rows )
{
for( int i = 0; i < rows; i++ )
array[ i ].resize( cols );
}
const vector<Object> & operator[]( int row ) const
{
return array[ row ];
}
vector<Object> & operator[]( int row )
{
return array[ row ];
}
int numrows( ) const
{
return array.size( );
}
int numcols( ) const
{
return numrows( ) ? array[ 0 ].size( ) : 0;
}
void resizeArray(int rows, int cols)
{
}
private:
vector< vector<Object> > array;
int rows;
int cols;
};
int main()
{
matrix<int> myMatrix(3,2);
//matrix<int> myMatrix1();
cout << myMatrix.numrows();
cout << "\n";
cout << myMatrix.numcols();
system("PAUSE");
return 0;
}