title: error: invalid declarator before function_name
body: <p>I have the following bit of code to return the scaled down value and its respective unit of measurement:</p>
  <pre><code>enum class convert_mode {up_metric, low_metric, metric, bit_metric, imperial}
  
  std::pair &lt;double, std::string&gt; auto_range (uint64_t x, int factor1 = 1000, int factor2 = 10){
  
          double val = (double) x;
          int i = 0;
          while (val &gt;= factor1 ){
                  val = val / factor1;
                  i++;
                  }
          switch (i) {
                  case 0 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;_&quot; );
                  case 1 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;K&quot; );
                  case 2 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;M&quot; );
                  case 3 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;G&quot; );
                  case 4 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;T&quot; );
                  case 5 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;P&quot; );
                  }
          
          return std::make_pair(0,&quot;_&quot;);
          }
  </code></pre>
  <p>that returns me the following error at compilation:</p>
  <pre><code>get_info.cpp:41:33: error: invalid declarator before ‘auto_range’
     41 | std::pair &lt;double, std::string&gt; auto_range (uint64_t x, int factor1 = 1000, int factor2 = 10){
        |                                 ^~~~~~~~~~
  get_info.cpp: In function ‘int main(int, char**)’:
  get_info.cpp:270:14: error: ‘auto_range’ was not declared in this scope
    270 |   auto x1 =  auto_range(PC.get_memory_info(), factor1, factor2);
        |              ^~~~~~~~~~
  </code></pre>
  <p>As a side-note the code did compile correctly previously and I inspired this method from the following answer : <a href="https://stackoverflow.com/questions/321068/returning-multiple-values-from-a-c-function">Returning multiple values from a C++ function</a></p>
  <p>Edit:</p>
  <ul>
  <li>The function should work like this:</li>
  </ul>
  <ol>
  <li>auto_range ( number_to_reduce, reduction_per_unit, reduction_of_digits )</li>
  <li>returns pair&lt; reduced_number, unit_of_measurement &gt;</li>
  </ol>
  <ul>
  <li>digit_rm is a function to remove the extardigits remained after the comma (12345m =&gt; 12.345Km =&gt; digit_rm(12.345,10) =&gt; 12.3Km).</li>
  </ul>
  <pre><code>double digit_rm (double val, int factor = 100){
      return (double)((int)(val*factor))/factor; 
      }
  
  </code></pre>
  <ul>
  <li>may <code>#include</code>'s in this case are the following :</li>
  </ul>
  <pre><code>#include &lt;sys/ioctl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt; 
  #include &lt;iomanip&gt;  // std::seprecision, std::fixed 
  #include &lt;math.h&gt;
  #include &lt;sys/statvfs.h&gt;
  #include &lt;cstring&gt;
  #include &lt;utility&gt;
  // See: https://man7.org/linux/man-pages/man2/sysinfo.2.html
  #include &lt;sys/sysinfo.h&gt;
  </code></pre>
  <ul>
  <li><p>I am using a Linux machine (Ubuntu 20.04.2 LTS x86_64), if that matters.</p>
  </li>
  <li><p>The <code>enum class</code> is a part of a future modification, if that is worth mentioning.</p>
  </li>
  <li><p>Here is an example :</p>
  </li>
  </ul>
  <pre><code>#include &lt;sys/ioctl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt; 
  #include &lt;iomanip&gt;  // std::seprecision, std::fixed 
  #include &lt;math.h&gt;
  #include &lt;sys/statvfs.h&gt;
  #include &lt;cstring&gt;
  #include &lt;utility&gt;
  // See: https://man7.org/linux/man-pages/man2/sysinfo.2.html
  #include &lt;sys/sysinfo.h&gt;
  
  double digit_rm (double val, int factor = 100){
      return (double)((int)(val*factor))/factor; 
      }
  
  enum class convert_mode {up_metric, low_metric, metric, bit_metric, imperial}
  
  std::pair &lt; double, std::string &gt; auto_range (uint64_t x, int factor1 = 1000, int factor2 = 10){
  
      double val = (double) x;
      int i = 0;
      while (val &gt;= factor1 ){
          val = val / factor1;
          i++;
          }
      switch (i) {
          case 0 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;_&quot; ); 
          case 1 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;K&quot; ); 
          case 2 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;M&quot; ); 
          case 3 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;G&quot; );
          case 4 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;T&quot; );
          case 5 : return std::make_pair( digit_rm( val, factor2 ) ,&quot;P&quot; ); 
          }
      
      return std::make_pair(0,&quot;_&quot;);
      }
  
  int main (int argc, char **argv)
  {
  
  double x = 1234567;          //say this is Hz
  auto y = auto_range(x);
  std::cout &lt;&lt; y.first &lt;&lt; &quot; &quot; &lt;&lt; y.second &lt;&lt; &quot;Hz&quot; &lt;&lt; std::endl;    //Should return 1.2Mhz
  
  return 0;
  }
  </code></pre>