我想从一个矩阵类中提取一列,其中的变量A
实现为<vector<vector<T> >
,像这样my_matrix(,2)
并且应该提取我的第二列。此外,我不想要一个函数名称get_col,因为我已经使用operator()重载来提取行。我试过了:在C++中从矩阵中提取列
template<class T>
vector<T> & operator()(void, const int& col){
vector<T> Result(rows,0);
for(int i=0;i<rows;++i)
Result[i]=this->A[i][col];
return Result;
}
有什么建议吗?
类包括:
template <class T> class QMatrix{
public:
int rows;
int cols;
vector<vector<T> > A;
这个语法在C++中是不可能的。 –
也许我们可以使用一个把戏:) – moldovean