Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Using TKey Class


Constructors

The constructors are used to set the following information:

For example:

TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpText aType)
    : TKey(anOffset,aType)
       {}

TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpText aType,TInt aLength)
    : TKey(anOffset,aType,aLength)
       {}

TKeyDerived::TKeyDerived(TInt anOffset,TKeyCmpNumeric aType)
       : TKey(anOffset,aType)
       {}

[Top]


Implementing the At() function

A typical implementation of the virtual function At(), which gets a pointer to the key of an element corresponding to a given index, might be structured:

TAny* TKeyDerived::At(TInt anIndex) const
       {
       if (anIndex==KIndexPtr)
        {
              return((TUint8 *)iPtr+iKeyOffset);
        }
       //
       // code to return a pointer to the key in the appropriate element
       //
       }

The derived class will need to have a pointer to the array it represents. At the very least, the derived class will need a data member for this pointer and, possibly, a member function to set it. This is needed in order to implement the At() function.

TKey and derived classes use untyped pointers, i.e. pointers of type TAny*. It may be desirable to provide type safety by further deriving a templated class.