Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Znav
nextSmart Pointers for Classes
prevC++ Mapping for Operations

On this page:

Table of Contents
maxLevel3

Basic C++ Mapping for Classes

...

There is quite a bit to discuss here, so we will look at each item in turn.

Ztop

Anchor
object
object

Inheritance from Ice::Object in C++

...

Wiki Markup
{zcode:slice}
["protected"] class TimeOfDay {
    short hour;         // 0 ? 23
    short minute;       // 0 ? 59
    short second;       // 0 ? 59
    string format();    // Return time as hh:mm:ss
};
{zcode}

Ztop

Class Constructors in C++

...

Note that single-parameter constructors are defined as explicit, to prevent implicit argument conversions.
By default, derived classes derive non-virtually from their base class. If you need virtual inheritance, you can enable it using the ["cpp:virtual"] metadata directive.

Ztop

Class Operations in C++

Operations of classes are mapped to pure virtual member functions in the generated class. This means that, if a class contains operations (such as the format operation of our TimeOfDay class), you must provide an implementation of the operation in a class that is derived from the generated class. For example:

...

Info

We discuss the motivation for the protected destructor in Preventing Stack-Allocation of Class Instances.

Ztop

Class Factories in C++

Having created a class such as TimeOfDayI, we have an implementation and we can instantiate the TimeOfDayI class, but we cannot receive it as the return value or as an out-parameter from an operation invocation. To see why, consider the following simple interface:

...

Wiki Markup
{zcode:cpp}
Ice::CommunicatorPtr ic = ...;
ic?->addObjectFactory(new ObjectFactory, M::TimeOfDay::ice_staticId());
{zcode}

...

Finally, keep in mind that if a class has only data members, but no operations, you need not create and register an object factory to transmit instances of such a class. Only if a class has operations do you have to define and register an object factory.

Ztop

See Also

Zret
Znav
nextSmart Pointers for Classes
prevC++ Mapping for Operations