给数组赋值时遇到问题。我创建了一个名为Treasury
。我创建了另一个类TradingBook
我想包含一个全局数组Treasury
可以从所有方法访问TradingBook
。这是我的 TradingBook 和 Treasury 的头文件:
class Treasury{
public:
Treasury(SBB_instrument_fields bond);
Treasury();
double yieldRate;
short periods;
};
class TradingBook
{
public:
TradingBook(const char* yieldCurvePath, const char* bondPath);
double getBenchmarkYield(short bPeriods) const;
void quickSort(int arr[], int left, int right, double index[]);
BaseBond** tradingBook;
int treasuryCount;
Treasury* yieldCurve;
int bondCount;
void runAnalytics(int i);
};
这是我收到错误的主要代码:
TradingBook::TradingBook(const char* yieldCurvePath, const char* bondPath)
{
//Loading Yield Curve
// ...
yieldCurve = new Treasury[treasuryCount];
int periods[treasuryCount];
double yields[treasuryCount];
for (int i=0; i < treasuryCount; i++)
{
yieldCurve[i] = new Treasury(treasuries[i]);
//^^^^^^^^^^^^^^^^LINE WITH ERROR^^^^^^^^^^^^^^
}
}
我收到错误:
不匹配'operator='
在线上'yieldCurve[i] = new Treasury(treasuries[i]);'
有什么建议吗?
那是因为yieldCurve[i]
属于类型Treasury
, and new Treasury(treasuries[i]);
是一个指向 a 的指针Treasury
目的。所以你有类型不匹配。
尝试改变这一行:
yieldCurve[i] = new Treasury(treasuries[i]);
to this:
yieldCurve[i] = Treasury(treasuries[i]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)