Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That is because array types decay to pointers when used as function parameters or when passed as function argument. In other words, <strong>your function signature is equivalent to</strong>:</p> <pre><code>template &lt;typename T&gt; inline T bigArry(const T* data) </code></pre> <p>The range-based <code>for</code> loop passes <code>data</code> to the global <code>std::begin()</code> and <code>std::end()</code> functions in order to get iterators to (respectively) the first and the one-past-the-last element of the container.</p> <p>Of course, there are no global <code>std::begin()</code> and <code>std::end()</code> functions that accept a <em>pointer</em>, and they couldn't be meaningfully defined either: how to determine the end of the container given just a pointer to its first element?</p> <p>You can use <code>std::array</code> instead of C arrays (<code>std::array</code> is a zero-overhead wrapper around a C array), and modify your calling function accordingly:</p> <pre><code>template &lt;typename T&gt; inline T bigArry(std::array&lt;T, 5&gt; data) // ^^^^^^^^^^^^^^^^ { T level = data[0]; for(T item : data) { if(level&lt;item){ level=item; } } return level; } int main() { std::array&lt;int, 5&gt; data = {1,2,3,4,5}; // ^^^^^^^^^^^^^^^^^^^^^^^ std::cout &lt;&lt; bigArry(data); return 0; } </code></pre> <p>Here is a <a href="http://coliru.stacked-crooked.com/view?id=077762de7ca7140694e66912bfce7e6c-a63ad9fea3739cb794a74965e5d28fb3"><strong>live example</strong></a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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