I've a little problem with the overloading of an operator. I've a class named AtmospheridData, in which I define the operator *.
In the header I define this method inside the class:
//! Operator * (scalar)
AtmosphericData operator*(const qreal& qrMult) const;
and the definition, in the .cpp file, is the following:
AtmosphericData AtmosphericData::operator*(const qreal& qrMult) const
{
AtmosphericData xResult;
xResult.m_qrTemperature = this->m_qrTemperature * qrMult;
xResult.m_qrPressure = this->m_qrPressure * qrMult;
xResult.m_qrDensity = this->m_qrDensity * qrMult;
xResult.m_qrAbsoluteHumidity = this->m_qrAbsoluteHumidity * qrMult;
xResult.m_qrVisibility = this->m_qrVisibility * qrMult;
xResult.m_qrPrecipitationIndex = this->m_qrPrecipitationIndex * qrMult;
xResult.m_xWind.qrNS = this->m_xWind.qrNS * qrMult;
xResult.m_xWind.qrEW = this->m_xWind.qrEW * qrMult;
xResult.m_xWind.qrVert = this->m_xWind.qrVert * qrMult;
xResult.m_xPrecipitationType = this->m_xPrecipitationType;
return xResult;
}
Then, I use the class in the following expression:
AtmosphericData c2;
AtmosphericData t1;
AtmosphericData t2;
AtmosphericData y0;
AtmosphericData y1;
qreal hx;
/* other code */
c2 = - (3 * (y0 - y1) + (hx * ((2 * t1) + t2))) / (hx * hx);
When I compile (using qmake-gcc under linux) I obtain the following error
error: no match for ‘operator*’ in ‘3 * AtmosphericData::operator-(const AtmosphericData&) const(((const AtmosphericData&)((const AtmosphericData*)(& y1))))’
I seems that I'm doing something wrong with the operator * declaration, but I don't understand what I am doing wrong.
Can anyone tell me how I can correct this error?
Thanks for your replies.