Re: Template class parameter

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C587EFA2-6680-40DE-A7DC-ACBDCBF9123A@xxxxxxxxxxxxx
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)?

For example:

template <size_t sz>
class FixedArray {
int a[sz];
public:
// Allows running STL algorithms over fixed array
int* begin();
int* end();
};

Try doing this with a parameter passed to constructor, without a heap
allocation.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Template return an error message
    ... //base template class ... Are you using VC6, by any chance? ... X<char, int> xii; ... Which part of "no appropriate default constructor" do you find difficult ...
    (microsoft.public.vc.language)
  • Re: Template class parameter
    ... int main ... Sometimes a template class is defined to have only parameter and no type ... If there is no type information ... The canonical example is a factorial class: ...
    (microsoft.public.vc.language)
  • Re: Template class parameter
    ... int main ... Sometimes a template class is defined to have only parameter and no type ... If there is no type information ... The canonical example is a factorial class: ...
    (microsoft.public.vc.language)
  • Facing problem in creating object of derived class (whish is derived from template class) and pushin
    ... void display; ... int main ... Also I want to know Is derived class is also a Template class? ...
    (microsoft.public.vc.stl)
  • g++ loop unrolling performance
    ... I am using the boost::array template class trying to generalize my ... can be determined at compile time or upon entry to the loop. ... The gcc switch ... int main ...
    (comp.lang.cpp)