title: Converting JavaScript function to C++
body: <p>I was working on a Dynamic Programming Problem and was able to code up a Javascript solution:</p>
  <pre><code>function howSum(targetSum,numbers,memo = {}){
      //if the targetSum key already in hashmap,return its value
      if(targetSum in memo) return memo[targetSum]; 
  
      if(targetSum == 0) return [];
      if(targetSum &lt; 0) return null;
  
      for(let num of numbers){
          let aWay = howSum(targetSum-num,numbers,memo);
          if(aWay !== null){
              memo[targetSum] = [...aWay,num];
              return memo[targetSum];
          }
      }
  
      //no way to generate the targetSum using any elements of input array
      memo[targetSum] = null;
      return null;
  }
  </code></pre>
  <p>Now I was thinking over how I could translate this into a CPP code.
  I would have to use a reference to an <code>unordered map</code> for the <code>memo</code> object.</p>
  <p>But how should I go about returning the <code>empty array</code> and <code>null</code> values as in the base condition?Should I return an <code>array pointer</code> and <code>realloc</code> it when inserting an element?Wouldnt that be a <code>C</code> way of programming it?
  Also how should I go about passing the <code>default parameter</code> to the <code>memo</code> unordered map in C++?Currently I have overloaded the function which creates the memo unorderd map and passes its <code>reference</code>.</p>
  <p>Any guidance will be appreciated as I can solve future questions.</p>