나는 함수를 통합하기 위해 gsl로 작업 중이다. 이 함수는 double과 void *를 입력으로 가지며 출력으로 double을 갖는 람다 함수로 만들어졌습니다. 변수 캡처없이 람다를 사용하면 모든 것이 잘 작동합니다. 그러나 변수 캡처를 수행하면 더 이상 작동하지 않습니다.람다 함수와 gsl의 수치 적 통합
누구나 왜 그렇게 설명 할 수 있습니까?
이이 하나가 잘 작동 :
여기 내 문제를 설명하기 위해 만들어 코드의 두 조각입니다
int main(int argc, char **argv)
{
double beg = 0;
double end = 10;
auto f = [] (double x, void * p) {return 2.0;};
gsl_integration_workspace * w = gsl_integration_workspace_alloc (GSL_INTEGRATION_WORKSPACE_SIZE);
double result;
double error;
gsl_function F;
F.function = f;
F.params = NULL;
gsl_integration_qags (&F, beg, end, 0, GSL_INTEGRATION_RELATIVE_PRECISION, GSL_INTEGRATION_WORKSPACE_SIZE, w, &result, &error);
cout<<result<<endl;
}
동안 라인
에이 일 개int main(int argc, char **argv)
{
double beg = 0;
double end = 10;
double p = 2.0;
auto f = [&] (double x, void * p) {return p;};
gsl_integration_workspace * w = gsl_integration_workspace_alloc (GSL_INTEGRATION_WORKSPACE_SIZE);
double result;
double error;
gsl_function F;
F.function = f;
F.params = NULL;
gsl_integration_qags (&F, beg, end, 0, GSL_INTEGRATION_RELATIVE_PRECISION, GSL_INTEGRATION_WORKSPACE_SIZE, w, &result, &error);
cout<<result<<endl;
}
수익률
F.function = f;
다음 오류 :
Assigning to 'double (*)(double, void *)' from incompatible type '<lambda at /[omissis]/main.cpp>'
이것은 내가 찾고있는 것입니다. –
마음에 드시면 다른 답변에 투표 할 수 있습니다 :) –
여기서'std :: function'은 어디에 있습니까? – Walter