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();
我必须做实施,通常我可以。但是这次我无法弄清楚如何处理T **
我很新手,你可以看到。在第一个我认为是双指针,但显然它不是。我只能使用给我的“iostream”头文件和Matrix类的接口头文件。
答案 0 :(得分:0)
请查看以下链接,它非常不言自明,并将指导您的实施(假设您知道如何在没有模板的情况下执行此操作):
http://www.cplusplus.com/doc/tutorial/templates/#class_templates
您将结束初始化课程:
Matrix<int> *myMatrix = new Matrix<int>(data, 10,10);
或
Matrix<int> myMatrix(10,10);
答案 1 :(得分:-1)
Matrix::Matrix(int numRows = 0, int numCols = 0)
:data(new T[numRows][numCols]){}
Matrix::~Matrix(){delete [] data;}
我会让自己弄清楚其余部分。