title: create different type of object by parameter in c++?
body: <p>I am new to c++, I want to create different type of object by parameter, like this:</p>
  
  <pre><code>if (version_ == "v1") {
      typename std::unordered_map&lt;T, TIndex&gt; uniq;
  } else {
      typename absl::flat_hash_map&lt;T, TIndex&gt; uniq;
  }
  
  uniq.reserve(2 * N);
  </code></pre>
  
  <p>However, this code compile failed:</p>
  
  <pre><code> error: 'uniq' was not declared in this scope
         uniq.reserve(2 * N);
         ^
  </code></pre>
  
  <p>Then, I change the code:</p>
  
  <pre><code>std::unordered_map&lt;T, TIndex&gt; uniq1;
  absl::flat_hash_map&lt;T, TIndex&gt; uniq2;
  auto uniq = uniq1;
  if (version_ == "v2") {
     uniq = uniq2;
  }
  uniq.reserve(2 * N);
  </code></pre>
  
  <p>It also filed:</p>
  
  <pre><code>error: no match for 'operator=' (operand types are 'std::unordered_map&lt;bool, long long int, std::hash&lt;bool&gt;, std::equal_to&lt;bool&gt;, std::allocator&lt;std::pair&lt;const bool, long long int&gt; &gt; &gt;' and 'absl::flat_hash_map&lt;bool, long long int, absl::hash_internal::Hash&lt;bool&gt;, std::equal_to&lt;bool&gt;, std::allocator&lt;std::pair&lt;const bool, long long int&gt; &gt; &gt;')
             uniq = uniq2;
                  ^
  </code></pre>
  
  <p>How can I implement this feature in c++?</p>