如果我理解正確你的問題,你都試圖定義矩陣爲模板,採取行類型和列類型,然後行類型(我假設也columnType)基質型的模板。我最大的問題是:實際數據在哪裏?在某種程度上,我認爲這個矩陣實際上應該分解爲一系列整數,或者雙精度或者字符,或者反轉指向布爾指針的迭代器等等。哪裏是?
你圓似乎是試圖讓太多架構的症狀。找出你想實際存儲在數據上,進行類數據類型的模板參數,然後讓所有其他相關的類或者主類,或數據類型的模板參數,以及哪個類。例如:
template <class DataType>
class Matrix{
//store the data in here: a DataType [], or vector<DataType>, or something
}
和:
template <class MatrixType>
class Row{
//has something which refers back to the original matrix of type MatrixType
}
或
template <class DataType>
class Row{
//has something which refers back to the original matrix of type Matrix<DataType>
}
我建議使用上述選擇的第二,因爲它使被更容易地指Row類中Matrix類,如:
template <class DataType>
Row<DataType> Matrix::getRow(int index){
//return an instance of Row<DataType> containing the appropriate row
}
你爲什麼試圖做到這一點,而不是根據底層數據類型(例如,數據類型)定義這些類中的一個(或兩個)。 int,double等)?對於這個問題,數據類型在哪裏定義/聲明? – tlayton 2010-06-22 17:55:32
行和列類型如何變化以提供不同的矩陣? 它是行和列改變的類型,還是隻是實例? – 2010-06-22 19:16:03