Ahot's weblog

Friday Oct 10, 2008

Just found one more solution for getting size of array with CPP. It's based on templates:
#include "stdafx.h"
#include <iostream>

template <class T, int size>
void f(T (&x)[size])
{
 std::cout<<size<<std::endl;
}

int main()
{
 int array[] = {1, 2, 3, 4, 5, 6, 7}; 
 f(array);

 int arrayTwo[] = {1, 2, 3};
 f(arrayTwo);

 return 0;
}

Comments:

how boring...

Posted by 88.116.47.214 on October 23, 2008 at 10:40 PM GMT+03:00 #

Yea
It's time to sleep...

Posted by ahot on March 30, 2009 at 10:48 PM GMT+03:00 #

thanks dude.
i really appreciate this.

Posted by peter on June 03, 2009 at 03:28 PM GMT+03:00 #

Post a Comment:
  • HTML Syntax: NOT allowed

FEEDS:

BOOKMARKS:

This blog copyright 2009 by ahot