我使用代码块构建了我的程序,但对于学校,我们应该通过 linux 系统进行编译。我在下面遇到了这些错误,但我在使用 149 时遇到了问题。我不知道它在抱怨什么。也许有人可以帮助我?
In file included from matrix.cpp:9:0:
matrixClass.h: In member function âT Matrix<T>::GetData(int, int) const [with T = int]â:
matrixClass.h:149:17: instantiated from âstd::ostream& operator<<(std::ostream&, const Matrix<int>&)â
matrix.cpp:22:13: instantiated from here
matrixClass.h:131:16: warning: converting to non-pointer type âintâ from NULL
我的代码如下。
T GetData(int row, int column) const
{
if (row>=0 && row<numrows() && column>=0 && column<numcols())
{
return pData[GetRawIndex(row, column)];
}
return NULL;
}
//Output matrix arrays here.
friend ostream& operator<<(ostream& os, const Matrix<T>& matrix)
{
os << "[";
for(int i = 0; i<matrix.numrows(); i++)
{
for(int j = 0; j < matrix.numcols(); j++)
os << matrix.GetData(i,j) << " ";
os << endl;
}
os << "]" <<endl;
return os;
}