멤버 변수로 두 개의 사용자 지정 개체가있는 아래 클래스가 있습니다. 굵게 표시된 부분에 오류가 발생합니다. 컴포지션 클래스의 보호 된 멤버에게 액세스하는 적절한 방법은 무엇입니까? 나는 f, gleft 및 gright 함수와 'u'크기를 조정하려고 할 때 오류가 발생합니다. 그것은 명시 적으로 friend
로 당신을 나열하지 않는컴포지션 클래스의 보호 된 멤버를 처리하는 중
class C
{
protected:
A x;
B y;
double a;
double b;
Eigen::MatrixXd u;
public:
double f(double x)
{
return x;
}
double gleft(double tau)
{
return tau
}
double gright(double tau)
{
return 0;
}
FD_Euro_Put(): x(), y(), a(0), b(0){}
FD_Euro_Put(char y1, double y2, double y3, double y4, double x2,
double x3, double x4, double x5, double x6, double x7):
x(x1, x2, x3, x4, x5, x6, x7)
{
double Xleft = x1*x2;
double Xright = x1*x3;
double Tauf = x1*x1;
double NN = floor((x1/x2);
a = x1*x2 - 0.5;
b = x1*x2 + 0.5;
pde = HeatPDE(y1, NN, Xleft, Xright, Tauf, Alpha); //begin problem area
u.resize(pde.N+1, pde.M+1);
if(fdtype == 'f')
u = pde.Forward_Euler(&f, &gleft, &gright);
else if(fdtype == 'b')
u = pde.Backward_Euler(&f, &gleft, &gright);
else if(fdtype == 'c')
u = pde.Crank_Nicolson(&f, &gleft, &gright); //end problem area
else
cout << "Incorrect choice for finite difference type!" << endl;
}
'x1'은 생성자의 서명에서 누락 된 것 같습니다 ... 또한 스택 오버플로에서 코드의 일부를 포맷 할 수 없습니다. 대신 코드 주석으로 섹션을 표시하십시오. – leemes