title: C++ return different objects
body: <p>i have a big problem.. I wonna select the Storage Service via a wrapper class. The returning value must be an object within the storage service class. I pasted my current approach. But my mindset didn't worked so far.</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>error: inconsistent deduction for auto return type: ‘SQL*’ and then ‘REDIS*’     return new REDIS();</p>
  </blockquote>
  
  <p>The big wish is to have an interface class which defines the struct and some "driver classes" which contains all necessary operations for the target storage service.</p>
  
  <p>I hope you have another approach, how I can solve this problem.. </p>
  
  <pre><code>    #include &lt;iostream&gt;
  
  
  class StorageTemplate {
      public:
          virtual bool UserhasSurName() = 0;
          virtual bool UserhasGivenName() = 0;
  };
  
  class SQL: public StorageTemplate {
      public:
          bool UserhasSurName() {
              //A SQL QUERY
              return true;
          }
          bool UserhasGivenName() {
              //AN ANOTHER SQL QUERY
              return true;
          }
  };
  
  class REDIS: public StorageTemplate {
      public:
          bool UserhasSurName() {
              //A REDIS CALL
              return false;
          }
          bool UserhasGivenName() {
              //A REDIS CALL
              return false;
          }
  };
  
  
  class controller {
      public:
          auto test(int select) {
              if( select == 1)
              {
                  return new SQL(); 
              } else {
                  return new REDIS();
              }
          }
  };
  
  
  
  int main(int argc, char const *argv[])
  {
      controller cont;
      auto schnitzel = cont.test(1);
      auto mitzel = cont.test(2);
      std::cout &lt;&lt; schnitzel-&gt;UserhasSurName() &lt;&lt; std::endl;
      std::cout &lt;&lt; mitzel-&gt;UserhasSurName() &lt;&lt; std::endl;
  }
  </code></pre>