title: C++ How to change the default value of enum in C++
body: <p>I am trying to override the default value of enum passed as a parameter, but I am getting the default value.</p>
  
  <pre><code>class MyClass
  {
  public:
      enum MyCalculation
      {
        SUM,
        DIVIDE,
        MULTIPLY,
        NOCALCULATION
      };
      void foo(MyCalculation cal = NOCALCULATION);
      void DoCalculation();
  };
  
  void MyClass::DoCalculation()
  {
   MyCalculation cal;
   // here I am getting the enum value at runtime
   int val = // get enum value
   switch(val)
   {
     case 0:
      cal = MyClass::SUM;
      break;
     case 1:
      cal = MyClass::DIVIDE;
      break;
     case 2:
      cal = MyClass::MULTIPLY;
      break;
   }
    foo(cal);
  }
  
  void MyClass::foo(MyCalculation getCal)
  {
   cout &lt;&lt; getCal;
  }
  </code></pre>
  
  <p>I tried passing by reference in DoCalculation method, but I am always getting NOCALCULATION in foo.
  Do I need to do something else?</p>