Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualCornstalks

Posted 25 February 2013 - 06:45 PM

Try passing int a[10] to a function and getting its size ;)

Also, you can do something like this:

template <typename T>
T doubleData(const T& v)
{
    T data = v; // Can't do this with an int a[10]
    for (typename T::value_type& value : data) // int a[10] certainly has no ::value_type member type
        value *= 2;

    return data; // Can't do this with an int a[10] either!
}
 
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!

Edit: Also, check out this article

Edit edit: good catch, Brother Bob!


#10Cornstalks

Posted 25 February 2013 - 05:26 PM

Try passing int a[10] to a function and getting its size ;)

Also, you can do something like this:

template <typename T>
T doubleData(const T& v)
{
    T data = v;
    for (typename T::value_type& value : data)
        value *= 2;

    return data;
}
 
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!

Edit: Also, check out this article

Edit edit: good catch, Brother Bob!


#9Cornstalks

Posted 25 February 2013 - 05:24 PM

Try passing int a[10] to a function and getting its size ;)

You can do something like this:
template <typename T>
T doubleData(const T& v)
{
    T data = v;
    for (typename T::value_type& value : data)
        value *= 2;

    return data;
}
 
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!
Edit: Also, check out this article

Edit edit: good catch, Brother Bob!

#8Cornstalks

Posted 25 February 2013 - 05:24 PM

Try passing int a[10] to a function and getting its size ;)

You can do something like this:
template <typename T>
T doubleData(const T& v)
{
    T data = v;
    for (typename T::value_type& value : data)
        value *= 2;

    return data;
}
 
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!
Edit: Also, check out this article

Edit edit: good catch, Brother Bob![/url]

#7Cornstalks

Posted 25 February 2013 - 05:23 PM

Try passing int a[10] to a function and getting its size [img=http://www.gamedev.net/
 
You can do something like
this:
template <typename T>
T doubleData(const T& v)
{
    T data = v;
    for (typename T::value_type& value : data)
        value *= 2;

    return data;
}
 
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!
Edit: Also, check out this article

Edit edit: good catch, Brother Bob!

#6Cornstalks

Posted 25 February 2013 - 05:22 PM

Try passing <span style="font-family:courier new , courier, monospace;">int a[10]</span> to a function and getting its size&nbsp;<img data-cke-saved-src="http://public.gamedev.net//public/style_emoticons/default/wink.png" src="http://public.gamedev.net//public/style_emoticons/default/wink.png" class="bbc_emoticon" title=":wink:" /><br />&nbsp;<br />You can do something like <a data-cke-saved-href="http://ideone.com/S5AOJH" href="http://ideone.com/S5AOJH">this</a>:<pre class="_prettyXprint _lang-auto _linenums:0">template &lt;typename T&gt;
T doubleData(const T&amp; v)
{
T data = v;
for (typename T::value_type&amp; value : data)
value *= 2;

return data;
}
&nbsp;
// You can call the above function with std::vector, std::array, etc., but not with int a[10]!
</pre>Edit: <a data-cke-saved-href="http://www.devx.com/cplus/Article/42114" href="http://www.devx.com/cplus/Article/42114">Also, check out this article</a><br /><br />Edit edit: good catch, Brother Bob!

PARTNERS