嗨 我在C++学习模板,所以我决定写一个模板类的矩阵类。在Matrix.h文件我写C++模板 - 矩阵类
#pragma once
#include "stdafx.h"
#include <vector>
using namespace std;
template<class T>
class Matrix
{
public:
Matrix();
~Matrix();
GetDataVector();
SetDataVector(vector<vector<T>> dataVector);
bool operator == (Matrix* matrix);
bool operator < (Matrix* matrix);
bool operator <= (Matrix* matrix);
bool operator > (Matrix* matrix);
bool operator >= (Matrix* matrix);
Matrix* operator + (Matrix* matrix);
Matrix* operator - (Matrix* matrix);
Matrix* operator * (Matrix* matrix);
private:
vector<vector<T>> datavector;
int columns,rows;
};
矩阵CPP视觉Stuio程序自动生成的代码默认构造
#include "StdAfx.h"
#include "Matrix.h"
Matrix::Matrix()
{
}
Matrix::~Matrix()
{
}
但是如果我想编译这个我得到一个错误
“矩阵':使用类模板 需要模板参数列表 错误在默认构造函数中的文件Matrix.cpp中 可能是什么问题?
你想`布尔运算符==(常量矩阵&矩阵)const;`而不是`bool运算符==(矩阵*矩阵);`。另外,不需要析构函数,因为std :: vector会自行清理。 – fredoverflow 2011-02-06 15:24:57
您还可以查看犰狳(http://arma.sourceforge.net/download.html)的源代码。来源很清楚,图书馆很棒。顺便说一句,它是唯一积极维护的像样的C++线性代数库。 – 2011-02-06 15:55:21