title: Template and const
body: <p>I guess what I'm trying to do it's impossible but I have this code:</p>
  
  <pre><code> 22 class Q
   21 {   
   22     int integer;
   23     int fractional;
   24     int word;
   25   public:
   26     Q(int i,int f) { this-&gt;integer = i; this-&gt;fractional = f; this-&gt;word = i+f;}
   27     const int get_i() {return (const int)this-&gt;integer;}
   28     const int get_f() {return (const int)this-&gt;fractional;}
   29     const int get_w() {return (const int)this-&gt;word;}
   30     
   31     friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Q&amp; q){ os &lt;&lt; "Q" &lt;&lt; q.integer &lt;&lt; "." &lt;&lt; q.fractional &lt;&lt; " (w:" &lt;&lt; q.word &lt;&lt; ")"; return os; }
   32 };
   33 
   34 
   35 const Q Q1_i = Q(1,10);
   36 const Q Q1_o = Q(0,11);
   37 
   38 const std::array&lt;Q,1&gt; input_queue_q = {Q1_i};
   39 const std::array&lt;Q,1&gt; output_queue_q = {Q1_o};
   40 
   41 
   42 int sc_main(int argc, char *argv[])
   43 { 
   44   ac_fixed&lt;Q1_i.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
   45   
   46   for(const Q &amp;input_q : input_queue_q)
   47   { 
   48     for(const Q &amp;output_q : output_queue_q)
   49     { 
   50       ac_fixed&lt;input_q.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
   51     }
   52   }
   53 }
  </code></pre>
  
  <p>When I try to compile I got the following error:</p>
  
  <pre><code>check_ac_one_over.cpp: In function ‘int sc_main(int, char**)’:
  check_ac_one_over.cpp:44:23: error: passing ‘const Q’ as ‘this’ argument of ‘const int Q::get_w()’ discards qualifiers [-fpermissive]
     ac_fixed&lt;Q1_i.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                         ^
  check_ac_one_over.cpp:44:23: error: call to non-constexpr function ‘const int Q::get_w()’
  check_ac_one_over.cpp:44:23: error: call to non-constexpr function ‘const int Q::get_w()’
  check_ac_one_over.cpp:44:46: note: in template argument for type ‘int’ 
     ac_fixed&lt;Q1_i.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                                                ^
  check_ac_one_over.cpp:44:51: error: invalid type in declaration before ‘;’ token
     ac_fixed&lt;Q1_i.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                                                     ^
  check_ac_one_over.cpp:50:30: error: passing ‘const Q’ as ‘this’ argument of ‘const int Q::get_w()’ discards qualifiers [-fpermissive]
         ac_fixed&lt;input_q.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                                ^
  check_ac_one_over.cpp:50:30: error: call to non-constexpr function ‘const int Q::get_w()’
  check_ac_one_over.cpp:50:30: error: call to non-constexpr function ‘const int Q::get_w()’
  check_ac_one_over.cpp:50:53: note: in template argument for type ‘int’ 
         ac_fixed&lt;input_q.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                                                       ^
  check_ac_one_over.cpp:50:58: error: invalid type in declaration before ‘;’ token
         ac_fixed&lt;input_q.get_w(),1,false,AC_TRN,AC_SAT&gt; mem;
                                                            ^
  make: *** [check_ac_one_over.o] Error 1
  </code></pre>
  
  <p>I guess the problem is that gcc think that Q1_i.get_w() can change. Is there a way to compile this code ? I would like to iterate and use that templated type using the class that I've defined above.</p>
  
  <p>Cheers,
  Stefano.</p>