C++???????????????
???????????? ???????[ 2013/12/31 13:32:26 ] ????????C++ ???????
#ifndef __H_MATRIX_H__
#define __H_MATRIX_H__
#include <vector>
using namespace std;
template<typename Object>
class matrix
{
public:
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;
}
private:
vector< vector<Object> > array;
};
#endif//__H_MATRIX_H__
test.cpp
#include "matrix.h"
#include <iostream>
using namespace std;
int main()
{
matrix<int> matrixArray(3??5);
int i??j;
for (i=0; i<matrixArray.numrows(); i++)
{
for(j=0; j<matrixArray.numcols(); j++)
matrixArray[i][j] = i+j;
}
for (i=0; i<matrixArray.numrows(); i++)
{
for(j=0; j<matrixArray.numcols(); j++)
cout<< matrixArray[i][j]<<ends;
cout<<endl;
}
return 0;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11