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 to enums, 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.
    std::map<minute_periods, int> factors;
That way factors[five] will give you an int, and not an enum like the vector would.  I'm guessing from your code this is what you want because the values 5, 10, 15 and 30 are outside your enum's range (which is from 0 to 3).
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