Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiler Error on code with GCC that worked on Windows
    text
    copied!<p>I have a simple piece of code that is giving me a compiler error. I've had no issues compiling and running this in a windows environment under Visual Studio, but now under linux, using gcc, I am having problems. Note I am using <strong>gcc 4.4.5</strong>, and using the <strong>-std=c++0x</strong> directive.</p> <p>This code snippet is in a header file, file_handling.h, which does include all the necessary libraries (vector, string, fstream, etc). The variable 'output_file' is a member of the LogFile object, and gets properly checked/instantiated/etc elsewhere. The code itself is trivially simple, which is why I am stumped:</p> <pre><code>template &lt;typename T&gt; void LogFile::put(std::string const &amp; header, std::vector&lt;T&gt; const &amp; data) { output_file &lt;&lt; header &lt;&lt; " " &lt;&lt; std::scientific &lt;&lt; data[0] &lt;&lt; std::endl; for (std::vector&lt;T&gt;::const_iterator value = (data.begin()+1); value &lt; data.end(); ++value) { output_file &lt;&lt; *value &lt;&lt; std::endl; } } </code></pre> <p>The compiler states:</p> <pre><code>In file included from file_handling.cpp:2: file_handling.h: In member function 'void LogFile::put(const std::string&amp;, const std::vector&lt;T, std::allocator&lt;_Tp1&gt; &gt;&amp;)': file_handling.h:132: error: expected ';' before 'value' file_handling.h:132: error: 'value' was not declared in this scope make: *** [file_handling.o] Error 1 </code></pre> <p>Why does gcc not see the in-situ declaration of 'value' as a const_iterator? I've tried the following as a sanity check:</p> <pre><code>template &lt;typename T&gt; void LogFile::put(std::string const &amp; header, std::vector&lt;T&gt; const &amp; data) { std::vector&lt;T&gt;::const_iterator value; output_file &lt;&lt; header &lt;&lt; " " &lt;&lt; std::scientific &lt;&lt; data[0] &lt;&lt; std::endl; for (value = (data.begin()+1); value &lt; data.end(); ++value) { output_file &lt;&lt; *value &lt;&lt; std::endl; } } </code></pre> <p>And receive the exact same compiler report. Given this looks simple, and worked fine in Visual Studio, what am I missing or misunderstanding about gcc and/or a Linux environment?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload