Having a problem when assigning a value to an array. I have a class I created called Treasury
. I created another class called TradingBook
which I want to contain a global array of Treasury
that can be accessed from all methods in TradingBook
. Here is my header files for TradingBook and 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);
};
And here is my main code where I'm getting the error:
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^^^^^^^^^^^^^^
}
}
I am getting the error:
No match for
'operator='
on the line'yieldCurve[i] = new Treasury(treasuries[i]);'
Any advice?
That's because yieldCurve[i]
is of type Treasury
, and new Treasury(treasuries[i]);
is a pointer to a Treasury
object. So you have a type mismatch.
Try changing this line:
yieldCurve[i] = new Treasury(treasuries[i]);
to this:
yieldCurve[i] = Treasury(treasuries[i]);
Treasury* yieldCurve;
yieldCurve
is a pointer to an array of Treasury
, not Treasury*
. Drop the new
at the line with error, or modify the declaration for it to be an array of pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With