需要帮助计算增益.遇到错误.请帮助
Need help calculating the gain. running into an errror. pls need assistance
我的程序是一个自动股票市场,它从文件中读取数据并将其打印在屏幕上或写入文件。 我能够读取文件并将其显示在屏幕上,但是我在尝试计算增益时遇到了错误。下面是我的代码:
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& operator>>(std::ifstream&, stockType&)':stockType.cpp:38:错误:"计算增益"未在此范围内声明
函数calculateGain
是类stockType
的成员;它是stockType
的一个实例可以做的事情。重载的operator>>
(不是stockType
的成员)在没有此类实例的情况下调用它,这是非法的。试试这个:
istream& operator>>(istream& ins, stockType& stock)
{
...
stock.calculateGain(stock.todays_close_price, stock.prev_close_price);
...
}
相关文章:
- 编译包含字符串的代码时遇到问题
- 需要帮助设置在C++中使用的Potrace
- 在指针的帮助下,文本文件中单词的频率
- 遇到新行时,有没有办法停止istream_iterator
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 需要帮助将结构数组传递给函数
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在 for 循环中查找问题时遇到困难
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 创建结构的数组时遇到分段错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我遇到分段错误?
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 在 NS3 中遇到了以下代码行.需要帮助理解它
- 我只需要一些调试帮助(C++)。我遇到了多个不确定如何解决的问题
- 需要帮助计算增益.遇到错误.请帮助