저는 C++을 처음 접했고 포인터를 사용하는 방법을 배우려고합니다. 좌표를 생성 한 다음 난수 생성기를 사용하여 임의의 방향으로 이동하는 다음 파일이 있습니다.표현식에는 함수 유형에 대한 포인터가 있어야합니다.
void methane_coords(double *&sigmaf_point)
double dummy_int = 1;
string dummystring;
string s;
ifstream Dfile;
std::stringstream out;
out << 1;
s = out.str() + ".TXT";
Dfile.open (s.c_str());
if (Dfile.fail())
{
return;
}
for (int i=0; i<dummy_int; i++)
{
Dfile >> sigmaf_point[i];
}
그때 다른 함수에서 사용 :
double initial_energy(double **coords_fluid, const double *box_size){
// Loop over all pairs of atoms and calculate the LJ energy
double total_energy = 0;
for (int i = 0; i <= n_atoms-1; i++)
{
sf1=sigmaf_point(coords_fluid[i][3]);
ef1=epsilonf_point(coords_fluid[i][3]);
// Energy fluid-fluid
for (int j = i+1; j <= n_atoms-1; j++)
{
sf2=sigmaf_point(coords_fluid[j][3]);
ef2=epsilonf_point(coords_fluid[j][3]);
double delta_x = coords_fluid[j][0] - coords_fluid[i][0];
double delta_y = coords_fluid[j][1] - coords_fluid[i][1];
double delta_z = coords_fluid[j][2] - coords_fluid[i][2];
// Apply periodic boundaries
delta_x = make_periodic(delta_x, box_size[0]);
delta_y = make_periodic(delta_y, box_size[1]);
delta_z = make_periodic(delta_z, box_size[2]);
// Calculate the LJ potential
s=(sf1+sf2)/2.0;
e=pow((ef1*ef2),0.5);
double r = pow((delta_x*delta_x) + (delta_y*delta_y) +
(delta_z*delta_z),0.5)/s;
double e_lj = 4*((1/pow(r,12.0))-(1/pow(r,6.0))/e);
total_energy = (total_energy + e_lj);
}
}
coords_fluid 그래서 같은 주요 파일에 작성됩니다
double **coords_fluid = new double*[5000];
값 sigmaf_point 텍스트 파일에서 입력
이제 문제는 sf1 = sigmaf_point (coords_fluid [i] [3])입니다.
sigmaf_point에 "함수 유형에 대한 포인터가 있어야합니다"라는 오류 메시지가 나타납니다. 나는 이것에 대해 다소 혼란 스럽다. 나는 그것이 변수를 호출하는 방법에 관한 것이지만 그것을 고칠 수는 없다고 생각한다.
건배
모든
에 배열 변화의 가정? – Default
Google에서 많은 정보를 찾을 수있는 오류 메시지가 표시됩니다. 이 문제를 해결하기 위해 어떤 조사를 했습니까? – Default