There's this line of code
and I'm not sure the significance of <>Code:typedef data_t data_array_t<>;
Thanks!
There's this line of code
and I'm not sure the significance of <>Code:typedef data_t data_array_t<>;
Thanks!
EDIT: Never mind, I don't know...
Devoted my life to programming...
Assuming the code is actual valid, it is a `typedef' of a template class that has default values for every parameter. In that case, it is significant in that the code would be invalid without them.
Soma
Code:template <typename T = int> class test{}; int main() { test<> t; }
What would it mean if valid?Assuming the code is actual valid..
If data_t is a templated class or function, then data_t<T> is a type, not data_t...What does it mean to typedef something which is not a type?
I didn't feel like building a test case to test, but the only way I can think of that it is valid is:
* data_t is a templated type with a default value, maybe the initial size of the array?
* data_array_t is now a type that corresponds to data_t<>.
O_o
What I meant was that my comments were assuming that the compiler you have is allowing some kind of extension to `typedef' a template. If the compiler tells you it is invalid, as it is according to the standard, then my comments aren't accurate.
The angle brackets are in the wrong place for such a `typedef'.data_array_t is now a type that corresponds to data_t<>.
Unless the compiler allows the extension, that makes just as little sense without a size.typedef data_t data_array_t[];
Soma
I have no idea if it's standard or not, but I've seen it before, and VC10 and gcc both accept the following:
EDIT: gcc accepts it with "-ansi -pedantic" without warningCode:typedef int array[]; // recursive array sum, demo only int foo(array x, int n) { if (n == 0) return 0; return x[0] + foo(x + 1, n - 1); }
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Ah, well, it is being treated exactly as if it had been `typedef' pointer in that context.
Still, in the context, you are correct; it is perfectly valid, but still, to my mind at least, doesn't make sense.
Soma
My guess is a compiler extension. The only other cases where the type wraps around an identifier like that are arrays and functions. But template types do not. But <> are a spare bracketing character in that context, and if a compiler vender wanted to have additional parameter to a type, outside the framework of templates, arrays, and functions, that would be one of the few ways that would be unambiguous.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.