我有一个类Sparse_Matrix,它允许我有效地使用稀疏矩阵。C++ MatLab构造函数重载
我想通过使用特定的(习惯)的关键字,例如上,身份等来实例化一个特定的矩阵
这是我的类声明(命名空间矩阵)
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
什么 “但无济于事。”具体是指? – JaredC
编译器错误是:'没有匹配的函数调用“Eye(int)”' – SunnyBoyNY