Modeling Services > Relations > One-to-one Relations > Constructing Ownership Relations
 
Constructing Ownership Relations
Ownership relations do not have a default constructor. Consequently, the initialization list of a constructor for the owner class must call the constructor of each relation declared in the class.
You can construct an ownership relation in two different ways:
*By passing a reference (*this) to the constructor of the origin-object:
class Person:
public IlsObject
{
 public:
   IlsOwns<Person,Car> car;
   Person(): car(*this){}
};
*By passing an additional argument providing the initial value of the relation:
class Person:
public IlsObject
{
public:
   IlsOwns<Person,Car> car;
   Person(CarP aCar): car(*this,aCar){}
};
If you do not specifiy an initial value, the relation will contain a null smart pointer. If you do, the relation will contain a smart pointer to the owned object specified.
In addition, you can provide an identifier of type IlsRelationId as a third argument. This identifier is used to invert relations. Typically, the value you put in this identifier is an enumerated type that behaves like a numeric type. For more information about this identifier, see Using Relation Identifiers with an Inverted Relation and Using Relation Identifiers with an Inverted List-Relation. The constructor can take a fourth argument of type IlsActivity. When this argument is set to ILS_ACTIVE, any modifications of the relation trigger the recalculation of derived data members whose value depends on that relation. Derived data members are discussed in Entry and Derived Data Members.

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.