C++ 使用「;这";模板类中的关键字

C++ 使用「;这";模板类中的关键字,c++,class,templates,compiler-errors,C++,Class,Templates,Compiler Errors,我定义了一个模板类,并通过以下方式重载了一个运算符: template<class T = bool> class SparseMatrix { public: SparseMatrix(int msize); //Multiplication by vectors or matrices SparseMatrix<double> operator *(SparseMatrix<T> &s); //Matrix expo

我定义了一个模板类,并通过以下方式重载了一个运算符:

template<class T = bool>
class SparseMatrix
{
public:
    SparseMatrix(int msize);
    //Multiplication by vectors or matrices
    SparseMatrix<double> operator *(SparseMatrix<T> &s);
    //Matrix exponentiation
    SparseMatrix<double> pow(int n);
};
template<class T>
SparseMatrix<double> SparseMatrix<T>::pow(int n)
{
    if (n == 2)
    {
        return (this * this); //ERROR
    }
    else
    {
        int i=0;
        SparseMatrix<double> s = this * this; 

        while (i < n-2)
        {
            s = s * this;
            i++;
        }
        return s;
    }

}
然而,当我转到
main
并编写类似
SparseMatrix u=t.pow(2)的内容时
我得到一个错误,指出
类型为'SparseMatrix*'和'SparseMatrix*'的操作数对二进制'operator*'无效。
。乘法对于
bool
矩阵定义得很好,正如我前面所说的,那么,为什么编译器会抱怨呢?我是否使用了
这个
?如何修复此错误


谢谢你的帮助

是指向对象的指针,而不是对象本身。解除触发
应该可以完成此操作。

是指向对象的指针,而不是对象本身。解除触发
应该可以达到目的。

您似乎忘记了
是指向对象的指针。如果您实际阅读了错误消息(其中提到类型
SparseMatrix*
),则应该非常明显。顺便说一句,所有
const
都丢失了。如果您实现
operator*=()
以及
operator*()
。您似乎忘记了
这是指向对象的指针。如果您实际阅读了错误消息(其中提到类型
SparseMatrix*
),则应该非常明显。顺便说一句,所有
const
都丢失了。如果您实现
operator*=()
以及
operator*
,您会发现它更容易、更有效。
template<class T>
SparseMatrix<double> SparseMatrix<T>::pow(int n)
{
    if (n == 2)
    {
        return (this * this); //ERROR
    }
    else
    {
        int i=0;
        SparseMatrix<double> s = this * this; 

        while (i < n-2)
        {
            s = s * this;
            i++;
        }
        return s;
    }

}