This snippet comes from here (the last example):
http://www.fi.muni.cz/usr/jkucera/tic/tic0169.html[
^] and the question demonstrates the problem with taking code out of context.
Eckel is talking about using built in types as template arguments. In my opinion the example is not explained fully.
He could have written:
Holder<float,> h;
and got the same output. However the use of the wrapper class for float, Number allows initialization of the value in the constructor.
Doing this:
int main() {
Holder<number,> h;
for(int j = 0; j < 20; j++)
cout << h[j] << endl;
}
we see that the the values are set to 0 in the constructor of Number.
If we do this:
int main() {
Holder<float,> h;
for(int j = 0; j < 20; j++)
cout << h[j] << endl;
}
then we have uninitialized values.