スパース行列を効率的に操作できるクラスSparse_Matrixがあります。
Upper、Identityなどの特定の(慣用的な)キーワードを使用して、特定のマトリックスをインスタンス化したいと思います。
これは私のクラス宣言(名前空間マトリックス)です
template <typename T>
class Sparse_Matrix
{
private:
int rows;
int cols;
std::vector<int> col;
std::vector<int> row;
std::vector<T> value;
...
事前に初期化されたオブジェクトを取得する方法はありますか?
Sparse_Matrix<int> = Eye(3);
3行3列の単位行列を返します。
私はコンストラクターのイディオムを見てきましたが、それらは私のクラスと互換性のない静的なタイプのソフトを必要とします(私は提案を受け入れていますが)。
私もこのコードを試しました:
template <typename T>
Sparse_Matrix<T> Eye(int size)
{
Sparse_Matrix<T> ma;
ma.IdentityMatrix(size);
std::cout << "Eye!" << std::endl;
return ma;
}
..。
Sparse_Matrix<int> blah = Eye(10);
しかし、役に立たない。
ありがとうございました、
SunnyBoyNY