Sometimes a template class is defined to have only parameter and no
type (e.g. class something) information. Like the below sample. My
question is, why define template class in this way (e.g. I can
implement in an alternative way to put the parameter into
constructor)? If there is no type information (e.g. class something),
there will be no benefits and reasons to use the template class. Any
comments?
Expand|Select|Wrap|Line Numbers
- #include <vector>
- #include <iostream>
- using namespace std;
- template <int sizeclass Foo {
- private:
- int limit;
- public:
- Foo()
- {
- limit = size;
- }
- };
- int main (int argc, char** argv)
- {
- Foo <100f1; // limit member of instance f1 is 100
- Foo <200f2; // limit member of instance f2 is 200
- return 0;
- }
thanks in advance,
George