. Advertisement .
..3..
. Advertisement .
..4..
As the title says, I am getting the “no match for operator in c++” error. How can I fix it so the error goes away? Here is my detail:
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^^^^^^^^^^^^^^
}
}
When I operated it and I received the error text:
No match for 'operator=' on the line 'yieldCurve[i] = new Treasury(treasuries[i]);'
I appreciate any help from you.
The cause: This error occurs because
yieldCurve[i]
belongs to typeTreasury
andnew Treasury(treasuries[i]);
refers toTreasury
objects. Therefore, it is a type mismatch.Solution:
Change this line:
to:
yieldCurve
is a pointer that points toTreasury
and notTreasury*
. Dropnew
at line 14 with error. Modify the declaration to make it an array of pointers.