meesa: I think you are confusing "typeid" with "typeof". typeof is not standard (yet) - only a gcc extension. It yield in the type of the parameter. But then again, sizeof(typeof(T)) is always the same as sizeof(T), so no need for typeof here either..
typeid is for returning meta information about objects. It returns an instance of type "type_info" which is a class and has a member function called "name()" and which in turn returns a "const char*". I thought before that it also could return "const wchar_t*" but I was wrong in that.
Hey, you could try this out. Get the typeid of a typid! ;-)
|
cout << typeid ( typeid(int) ).name() << endl;
|
My compiler prints "class type_info".
At no point should you ever need to "find" the size of an array. It's supposed to be known at all times. |
I second that. If you use C-style arrays, there should be no uncertainity about the size of the array. If you still can't live without, at least use:
sizeof(array) / sizeof(*array)
or
sizeof(array) / sizeof(array[0])
which is the same (as helios already pointed out).
There is a library "boost::array" which has practically no overhead over an C-style array, but which provides better means to obtain the size of an array. You could also just use std::vector and have "very little" overhead.
Ciao, Imi.