In the Bjarne Stroustrup C++ Book (chapter 13, page 331), it said that “a template parameter can be used in the definition of subsequent template parameter”. And it gives the following code:
template<class T, T def_val> class Cont{ /* ... */ }
Can anyone provide an example of how to use this template. For example, how to initialize an object of Cont? It look to me that “def_val” is not a type argument, and should not be placed in <>. Am I wrong?
Thanks a lot
You can do something like this:
Template parameters aren’t required to be types.
This only works when
Tis an integral type (int,unsigned,long,charetc but notfloat,std::string,const char*, etc), as @Riga mentioned in his/her comment.