0

我有以下类,我尝试访问基类的受保护成员,但在 eclipse 中出现错误“无法解析字段分解”。有人可以向我解释我做错了什么吗?为什么我无法访问变量mFactorized

基类

template <typename ValueType>
class AbstractDirectLinearSolver{
protected:
    bool mFactorized;
public:
    //Constructors, destructor
    AbstractDirectLinearSolver(){
        mFactorized = false;
    }

    virtual ~AbstractDirectLinearSolver();

    //Methods
    virtual void Solve(Vector<ValueType>& x, const Vector<ValueType>& b) const = 0;
    virtual void Factorize(AbstractMatrix<ValueType>& A) = 0;
};

派生类

#include "AbstractDirectLinearSolver.hpp"

template<typename ValueType>
class CholeskySolver: public AbstractDirectLinearSolver {
private:
    AbstractMatrix<ValueType> *mR; //Pointer = Abstract class NOT ALLOWS instantiation !!
public:
    CholeskySolver() {
        mR = NULL;
    }

    ~CholeskySolver() {
        if (this->mFactorized) {  //ERROR HERE
            delete mR;
        }
    }

    void Solve(const Vector<ValueType>& x, const Vector<ValueType>& b) {
        Vector<ValueType> y(mR->ApplyLowInv(b));
        x = mR->ApplyLowerTransponse(y);
    }

    void Factorize(AbstractMatrix<ValueType>& A) {
        if (mR != NULL)
            delete mR;
        mR = NULL;
        A.CholeskyFactorization(mR);
        this->mFactorized;           //ERROR HERE
    }
};
4

2 回答 2

2

您正在尝试从类模板而不是类继承。将类标题更改为:

template<typename ValueType>
class CholeskySolver: public AbstractDirectLinearSolver<ValueType>
                                                       ^^^^^^^^^^^

看起来编译器在抱怨mFactorized不是成员(因为它不知道基类)之后,但在抱怨基类说明符无效之前退出了。

如果您要注释掉有问题的行,那么您会得到一个稍微好一点(尽管仍然相当混乱)的错误:expected class-name before ‘{’ token.

于 2012-11-23T11:44:32.880 回答
0
if (this->Factorized) 

应该

if (this->mFactorized)

第二个错误...

this->mFactorized;           //ERROR HERE

除了它没有做任何事情之外......我认为应该没有问题。

于 2012-11-23T11:30:00.380 回答