I’m having a strange issue with my code (or perhaps I’m just a bit rusty): The following code:
#include <iostream>
#include <vector>
using namespace std;
typedef vector<double> vDouble;
typedef vector<int> vInt;
//Class for calculations
class CallCosts
{
CallCosts::CallCosts();
CallCosts::CallCosts(vDouble nrates(4, 0)); //Constructor
void CallCosts::setRates(vDouble sr(4, 0));
void CallCosts::getTotals(vDouble gt(4, 0), vInt minutes(4, 0));
vDouble rates(4, 0);
vDouble totals(4, 0);
};
The compiler gives me an error on line 16:
CallCosts::CallCosts(vDouble nrates(4, 0)); //Constructor
The error is: expected ‘,’ or ‘…’ before ‘(‘ token.
Now I’m pretty sure I haven’t missed a ; anywhere, so what else could be causing this? Another note: I was using plain variables instead of the typedefs previously, and the code worked, so that’s probably the issue, but further than that I’m not sure?
Thanks in advance.
Remove
CallCosts::inside the class declaration.Also, what is this
CallCosts::CallCosts(vDouble nrates(4, 0));supposed to mean?If you want a constructor with parameter of type
vDouble, useCallCosts(vDouble nrates).If you want to specify a default value, do this
CallCosts(vDouble nrates= vDouble(4, 0));and remove the default constructor.