我试图制作一个嵌套的策略模式。在将嵌套父类设为纯虚拟时出现错误。这个想法甚至可能吗?
例子:
class Jacobi {
private:
mat _V, _A;
int _n, _rotations;
public:
class DiagAlg {
public:
virtual void diagonalize() = 0;
};
class Cyclic : DiagAlg {
public:
void diagonalize();
};
vec getE();
mat getV();
mat getA();
int getRotations();
Jacobi(Jacobi::DiagAlg DA);
Jacobi(const mat& A); // could be done without user supply of base vectors
bool rotate(int p, int q);
};
导致以下错误:
jacobi.h:28:26: error: cannot declare parameter ‘DA’ to be of abstract type ‘Jacobi::DiagAlg’
jacobi.h:15:9: note: because the following virtual functions are pure within ‘Jacobi::DiagAlg’:
jacobi.h:17:16: note: virtual void Jacobi::DiagAlg::diagonalize()
实现将在原因的 cpp 文件中。