Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Class types


Overview

Applications on the Symbian platform use four general kinds of class. The kinds are as follows:

These types are closely related to the requirements of cleanup support, which is described in more detail in Cleanup requirements.

[Top]


Value types—T classes

The most fundamental types are value types. These are given type, or class, names beginning with T.

The consequences of these fundamental characteristics are explored below.


Constructor

Many T types are simple enough not to need a constructor. Those that do, use the constructor to initialise member data.


Copy constructor and assignment operator

A copy constructor (TX(const TX&)) or assignment operator (TX& operator=(const TX&)) are rarely needed. This is because copying is always shallow, and almost always involves only a memberwise copy of the source T object to the destination. This is the default behaviour for the compiler-generated C++ copy constructor and assignment operator.

These functions may be needed if the T class is a templated class, parameterised by an integer length, which is also contained as a member of the class. Then, copying or assigning a TX<32> to a TX<40> would require more sophistication than a bitwise copy, so a copy constructor and assignment operator would have to be explicitly coded.


Destructor

T types have no C++ destructor. None is needed, because no external resources need to be cleaned up when a T object goes out of scope.


Orphaning

T types may safely be orphaned on the stack. Orphaning implies that the memory is deallocated without calling the destructor. Because T types do not own external resources, no external resources can become inaccessible when a T object is orphaned.


Function arguments

T types may be passed by value, as well as by reference, in function arguments.


Data members

T types may contain other T type objects. In addition, they may contain R objects, or pointers to C objects, provided these objects are owned by another class or function, which is responsible for these objects’ cleanup. In practice, this rarely occurs.


Built-in C++ types

All built-in C++ types satisfy the criteria for T classes. Built-in types are given typedef names beginning with T, e.g. TInt.

[Top]


Standard class hierarchy—C classes and class CBase

Most classes that are not T classes are C classes, which are derived, directly or indirectly, from class CBase.

CBase-derived classes have the following properties:

The requirements of C classes are documented in Two Phase Construction.

[Top]


Resource types—R classes

R classes are proxies for objects owned elsewhere. There are two main motivations for this:

The following are key characteristics of R objects:

R classes use a variety of protocols to meet these needs:

[Top]


Inteface types—M classes

M classes define abstract protocols, or interfaces. Concrete implementations of an interface defined by an M class are provided by derived protocol provider classes.

M classes have the following restrictions:

M classes often contain pure virtual functions that define a fully abstract interface. Some M classes implement some or all member functions, though within the restrictions given above.

M classes are the only use of multiple inheritance in the Symbian platform. For details of this, see Multiple inheritance and interfaces.