-1
我對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出現錯誤「表達式必須有指向函數類型的指針」。我對此有點困惑,我知道這是關於如何調用變量,但似乎無法修復它。
乾杯
你可以提供一個[SSCCE](http://sscce.org/)? – Default
當我谷歌的錯誤消息,我發現了很多信息。你爲了解決這個問題做了什麼調查? – Default