title: Accessing a protocol buffer extension repeated field from C++
body: <p>In the following protocol buffer, how does one access the repeated fields in the extension from C++?</p>
  
  <p>base.proto</p>
  
  <pre><code>message Base {
      optional int32 id = 1;
      repeated int32 ids = 2;
      optional string name = 3;
      repeated string names = 4;
      extensions 1000 to 1999;    
  }
  </code></pre>
  
  <p>ext.proto</p>
  
  <pre><code>import "base.proto";
  
  extend Base {
      repeated string names = 1000;
      optional int32 number = 1001;
      repeated int32 numbers = 1002;
      optional string name = 1003;
  }
  </code></pre>
  
  <p>The following doesn't compile (in VS2010)</p>
  
  <pre><code>#include "base.pb.h"
  #include "ext.pb.h"
  
  using namespace ::google::protobuf;
  
  int main(int argc, char *argv[])
  {
      Base b;
      RepeatedPtrField&lt;std::string&gt; base_names = b.names(); // OK
      RepeatedField&lt;int&gt; base_ids = b.ids(); // OK
  
      int ext_number = b.GetExtension(number); // OK
      std::string ext_name = b.GetExtension(name); // OK
      assert( b.HasExtension(numbers) ); // OK
      assert( b.HasExtension(names) ); // OK
      int32 i = b.GetExtension(numbers); // ? Compiles but doesn't make sense.
      RepeatedField&lt;int32&gt; ext_numbers = b.GetExtension(numbers); // compilation fails:
      RepeatedPtrField&lt;std::string&gt; ext_names = b.GetExtension(names); // compilation fails:
      return 0;
  }
  </code></pre>
  
  <p>Compilation errors</p>
  
  <pre><code>1&gt;test_proto.cpp(17): error C2440: 'initializing' : cannot convert from 'int' to 'google::protobuf::RepeatedField&lt;Element&gt;'
  1&gt;          with
  1&gt;          [
  1&gt;              Element=google::protobuf::int32
  1&gt;          ]
  1&gt;          No constructor could take the source type, or constructor overload resolution was ambiguous
  1&gt;\test_proto.cpp(18): error C2440: 'initializing' : cannot convert from 'const std::string' to 'google::protobuf::RepeatedPtrField&lt;Element&gt;'
  1&gt;          with
  1&gt;          [
  1&gt;              Element=std::string
  1&gt;          ]
  1&gt;          No constructor could take the source type, or constructor overload resolution was ambiguous
  </code></pre>