title: Overloading the global type conversion operator
body: <p>To test and display the result of some functions of my library, I am creating a set of handy functions.</p>
  
  <p>I have an <code>execute</code> function that looks like :</p>
  
  <pre><code>template &lt;typename R, typename I&gt;
  std::string execute( const std::string&amp; func_name, R(*func_ptr)( const I&amp; ), const I&amp; func_input );
  </code></pre>
  
  <p>It calls the function, and display the results and arguments in a formatted string that I can send to <code>std::cout</code>.</p>
  
  <p>The problem is that some of my functions do not return <em>convertible-to-string</em> results. I thought I could simply overload the global <code>::operator std::string</code> with something like:</p>
  
  <pre><code>template &lt;typename T&gt;
  operator std::string( const std::vector&lt;T&gt;&amp; v );
  </code></pre>
  
  <p>But GCC complains:</p>
  
  <pre><code>error: 'operator std::string(const std::vector&lt;T, std::allocator&lt;_CharT&gt; &gt;&amp;)' must be a nonstatic member function
  </code></pre>
  
  <p>Well, the problem of course is that I cannot add member operators to <code>std::vector</code>, and even for my classes, I don't want to pollute them with <em>"for testing"</em> conversion operators.</p>
  
  <p>I guess that I can add a layer of indirection and use a function instead of a conversion operator, but that would not be the more aesthetic solution. I could also overload <code>::operator &lt;&lt;</code> for <code>std::ostream</code> and use a <code>std::ostringstream</code>, but that also is not the cleanest solution.</p>
  
  <p>I wondered if the global conversion operator is really not overloadable, and if so, why.</p>