title: Using the type conversion operator
body: <p>I have a visual studio 2008 C++ application where I need to get information from a function that takes a variably sized buffer. So, I have a class that backs that type with a <code>std::vector</code> and implements a conversion operator to the type I want. </p>
  
  <pre><code>class CMibIpForwardTable
  {
  public:
      operator MIB_IPFORWARDTABLE* () 
      { 
          return reinterpret_cast&lt; MIB_IPFORWARDTABLE* &gt;( &amp;buffer_.front() ); 
      }
  
      ULONG size() const
      {
          return buffer_.size();
      }
  
      void resize( ULONG size )
      {
          buffer_.resize( size );
      }
  
  private:
      std::vector&lt; BYTE &gt; buffer_;
  };
  
  CMibIpForwardTable Get( DWORD* error_code = NULL )
  {
      CMibIpForwardTable table;
      ULONG size = 0;
  
      DWORD ec = ::GetIpForwardTable( NULL, &amp;size, FALSE );
      if( ec == ERROR_INSUFFICIENT_BUFFER )
      {
          table.resize( size );
          ec = ::GetIpForwardTable( table, &amp;size, TRUE );
      }
  
      if( NULL != error_code &amp;&amp; ec != 0 ) 
          *error_code = ec;
      return table;
  }
  </code></pre>
  
  <p>I would like to be able to use it like this:</p>
  
  <pre><code>CMibIpForwardTable table = Get();
  
  // error: 'dwNumEntries' : is not a member of 'CMibIpForwardTable'
  DWORD entries = table-&gt;dwNumEntries;
  </code></pre>
  
  <p>Is there a good way to get access to the underlying type <code>MIB_IPFORWARDTABLE</code>? Or am I stuck doing something like this:</p>
  
  <pre><code>MIB_IPFORWARDTABLE* t = table;
  DWORD entries = t-&gt;dwNumEntries;
  </code></pre>
  
  <p>Thanks,
  PaulH</p>