开发者

What does here UserArray means?

What does the below syntax represents?

typedef UserArray<T,W,L,H> MyType;

where:

  • T = type of an array element
  • W = width of an array element, 0 < W < 8
  • L = low bound of array index (preferably zero)
  • H = high bound of array index

Can anyone explain me using example for above declaration?

Does this 开发者_运维问答concepts comes under STL?


UserArray is a class template that takes four template parameters.

It's probably defined like that:

template<class T, int W, int L, int H> // parameter names might differ
class UserArray
{
    // ...
};

typedef is used to define aliases for types. This:

typedef UserArray<T,W,L,H> MyType;

Defines an alias for UserArray using the specified template parameters. T must be a type, and W, L and H must be compile-time integer constants. The resulting alias is called MyType, and using it is like using UserArray with the same parameters.

Those techniques are used to simplify typing when a type is used a lot in many places. For instance, you can do this:

typedef std::vector<int> IntVector;

IntVector vect; // a vector of ints


UserArray should be a container class template, something like below:

template<typename TYPE, unsigned int SIZE, int LOWER_BOUND, int HIGHER_BOUND>
class UserArray {
//...
};

So if you declare it as,

typedef UserArray<int,100,0,99> MyType;

Which means MyType is an array of 100 ints; it's lower bound is 0 and higher bound is 99. So the type should play within the range of 0 to 99. However, I don't feel that Lower and Higher bound are needed; because array size states everything.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜