I have the following code:
class mph {
public:
enum minute_periods {five, ten, fifteen, thirty};
std::vector<minute_periods> factors;
minute_periods fac;
void setUpFactors(void) {
factors.resize(4);
factors[five] = 5;
factors[ten] = 10;
factors[fifteen] = 15;
factors[thirty] = 30;
}
and I get the following error:
error: invalid conversion from ‘int’ to ‘mph::minute_periods’
how do I fix it?
int‘s are not implicitly cast toenums, you have to do it explicitly which is why you’re getting the error. I don’t think this code will do what you want it to however, it looks like you want something like this.That way
factors[five]will give you an int, and not anenumlike the vector would. I’m guessing from your code this is what you want because the values 5, 10, 15 and 30 are outside yourenum‘s range (which is from 0 to 3).