You can define friend classes and friend functions in your Rational® Rhapsody® model,
and the appropriate code will be generated.
To define a friend class:
- Add a dependency from the class whose data will be made available
to the class that needs to access this data.
- Apply the Friend stereotype to the dependency.
If the dependency is drawn from class A to class B, the code generated
for class A will contain the following declaration:
friend class B;
To define a Friend function:
- Add a dependency from the class whose data will be made available
to the function that needs to access this data.
- Apply the friend stereotype to the dependency.
If the dependency is drawn from class A to function getInfo(),
the code generated for class A will contain the following declaration:
friend void getInfo();
Note: Only a stand-alone function can be declared as a friend. If
you try to declare a single operation of a class as a friend, Rational Rhapsody will
not generate the correct code.