以下代码的预期结果应该是 505.5,但它返回的是 3.97541e+70。为什么会这样?如何解决问题?
#include <iostream>
#include <string>
using namespace std;
class Position {
public:
Position(int s, double p, string n) {
shares = s;
price = p;
name = n;
}
double getBpEffect() {
return bpEffect;
}
private:
string name;
int shares;
double price;
double bpEffect = (shares*price) / 2;
};
int main() {
Position xyz = Position(100, 10.11, "xyz");
double buyingPower = xyz.getBpEffect();
cout << buyingPower;
system("pause");
return 0;
}