| Znav |
|---|
| next | Smart Pointers for Classes |
|---|
| prev | C++ Mapping for Operations |
|---|
|
On this page:
Basic C++ Mapping for Classes
...
There is quite a bit to discuss here, so we will look at each item in turn.
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} |
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.
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. |
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.
See Also
| Znav |
|---|
| next | Smart Pointers for Classes |
|---|
| prev | C++ Mapping for Operations |
|---|
|