Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCornstalks

Posted 25 February 2013 - 05:30 PM

Try passing int a[10] to a function and getting its size wink.png

 
You mean like this?
template <class T, int N>
void printSizeOfArray(const T (&)[N])
{
    std::cout << N << std::endl;
}

Exactly. I wasn't saying you couldn't, but now you've just written the ugly code yourself instead of using std::array. The ugly code has got to live somewhere. You might as well let it live outside of your own code. It's even uglier if you're passing multiple array structures.


#1Cornstalks

Posted 25 February 2013 - 05:28 PM

Try passing int a[10] to a function and getting its size wink.png

 
You mean like this?
template <class T, int N>
void printSizeOfArray(const T (&)[N])
{
    std::cout << N << std::endl;
}

Exactly. I wasn't saying you couldn't, but now you've just written the ugly code yourself instead of using std::array. The ugly code has got to live somewhere. You might as well let it live outside of your own code.


PARTNERS