你好stackoverflow的人,
我是 C++ 的新手。我试图创建一个类,但是当我编译我的程序时,我当然会收到错误消息。我在这里希望你们中的一些人能告诉我我的程序有什么问题以及我做错了什么!
PS:我使用的是 OpenFOAM,所以有些不同,例如“.C”扩展名(而不是“.cpp”)和 Foam 库的使用。
船只.H
#ifndef Vessels_H
#define Vessels_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
class Vessels
{
public:
Vessels(double xCoordinate, double yCoordinate, double zCoordinate, double vesselLength, double vesselRadius, double P_outside, double P_inside);
int pointIndex();
double flowRate();
double wellModel();
private:
double m_xCoordinate, m_yCoordinate, m_zCoordinate, m_vesselLength, m_vesselRadius, m_P_outside, m_P_inside;
double flow, meshVolume, meshSize, equivalentRadius;
int index;
};
#include "Vessels.C"
#endif
船只.C
#include "Vessels.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// CONSTRUCTOR
Vessels::Vessels(double xCoordinate, double yCoordinate, double zCoordinate, double vesselLength, double vesselRadius, double P_outside, double P_inside) : m_xCoordinate(xCoordinate), m_yCoordinate(yCoordinate), m_zCoordinate(zCoordinate), m_vesselLength(vesselLength), m_vesselRadius(vesselRadius), m_P_outside(P_outside), m_P_inside(P_inside)
{
}
// METHODS
// Corresponding index for point (xCoordinate,yCoordinate,zCoordinate)
int Vessels::pointIndex()
{
return mesh.findCell(point(m_xCoordinate,m_yCoordinate,m_zCoordinate));
}
// Calculation of flow rate in the vessel using the Hagen-Poiseuille equation
double Vessels::flowRate()
{
return M_PI*Foam::pow(m_vesselRadius,4.0)/(8.0*mu.value*m_vesselLength)*(m_P_inside-m_P_outside);
}
// Numerical well model
double Vessels::wellModel()
{
Vessels vessel(double xCoordinate, double yCoordinate, double zCoordinate, double vesselLength, double vesselRadius, double P_outside, double P_inside);
index = vessel.pointIndex();
flow = vessel.flowRate();
meshVolume = mesh.V()[index];
meshSize = Foam::pow(meshVolume,1.0/3);
equivalentRadius = 3.0*meshSize/(3.0+2.0*M_PI*meshSize);
m_P_inside = P[index] + mu.value*flow/(4.0*M_PI*K)*(1.0/equivalentRadius - 1.0/m_vesselRadius);
return m_P_inside;
}
如果任何人都对它感兴趣,那么到目前为止,这是我的编译器错误:
Vessels.C: In member function ‘double Vessels::flowRate()’:
Vessels.C:65:52: erreur: invalid operands of types ‘double’ and ‘<unresolved overloaded function type>’ to binary ‘operator*’
Vessels.C: In member function ‘double Vessels::wellModel()’:
Vessels.C:73:18: erreur: request for member ‘pointIndex’ in ‘vessel’, which is of non-class type ‘Vessels(double, double, double, double, double, double, double)’
Vessels.C:74:17: erreur: request for member ‘flowRate’ in ‘vessel’, which is of non-class type ‘Vessels(double, double, double, double, double, double, double)’
Vessels.C:79:35: erreur: invalid operands of types ‘<unresolved overloaded function type>’ and ‘double’ to binary ‘operator*’
Vessels.C: In member function ‘double Vessels::flowRate()’:
Vessels.C:66:1: attention : contrôle a atteint la fin non void de la fonction [-Wreturn-type]
谢谢你!为了更好地理解如何使用 C++,我愿意接受所有可能的建议!