我的程序是一個自動化的股票市場,它從文件中讀取數據並將其打印出來或寫入文件。我能夠讀取文件並將其顯示在屏幕上,但我遇到了試圖計算增益的錯誤。 下面是我的代碼:需要幫助來計算增益。發生錯誤。請你需要幫助
istream& operator>>(istream& ins, stockType& stock)
{//member variables are all declared as a double
ins>>stock.todays_open_price
>>stock.todays_close_price
>>stock.todays_high_price
>>stock.prev_low_price
>>stock.prev_close_price;
calculateGain(stock.todays_close_price, stock_prev_close_price);
return ins;
}
void stockType::calculateGain(double close, double prev)
{ // gain was declared in the header file as a private member
//variable to store the gain calculated.
gain = ((close-prev)/(prev));
}
ostream& operator<<(ostream& outs, const stockType& stock)
{
outs<<stock.getOpenprice()
<<stock.getCloseprice()
<<stock.getPrevLowPrice()
<<stock.getPrevClosePrice()
<<stock.getGain()
return outs
}
//double getGain() was declared in the header file also as
double getGain() {return gain;}
下面
是錯誤即時得到: stockType.cpp:在函數 '的std :: ifstream的&操作>>(性病:: ifstream的&,stockType &)': stockType .cpp:38:錯誤:'calculateGain'未在此範圍內聲明
它是stockType的一個成員。我在頭文件中聲明它。 – Emy