我有以下类,我尝试访问Base类的受保护成员但是我在eclipse中收到错误“Field Factorized无法解析”。有人可以向我解释我做错了什么吗?为什么我无法访问变量mFactorized
??
BASE CLASS
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;
};
DERIVED CLASS
#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
}
};
答案 0 :(得分:2)
您正在尝试从类模板而不是类继承。将类标题更改为:
template<typename ValueType>
class CholeskySolver: public AbstractDirectLinearSolver<ValueType>
^^^^^^^^^^^
看起来编译器在抱怨mFactorized
不是成员(因为它不知道基类)之后,但在抱怨基类说明符无效之前就退出了。
如果你要评论有问题的行,那么你会得到一个稍微好一点(但仍然相当令人困惑)的错误:expected class-name before ‘{’ token
。
答案 1 :(得分:0)
if (this->Factorized)
应该是
if (this->mFactorized)
第二个错误......
this->mFactorized; //ERROR HERE
除了它没有做任何事情......我不认为应该有问题。