Troubleshooting
Problem
What's the difference between "forward reference" and "inclusion" for the KindInHeader and KindInImplementation field in the Dependency Specification and how do you use these settings appropriately?
Resolving The Problem
A dependency relationship indicates that a client class depends on a supplier class to provide certain services. For example, consider a class called SourceClass that references another class called TargetClass. This relationship can be modeled in Rose RealTime with a dependency between the client (SourceClass) and the supplier (TargetClass).
For complete details explaining how to create a dependency between two classes, please refer to the following section in Rose RealTime's Online Help:
Toolset Guide > Creating Class Diagram > Creating Dependency Relationships
Note: The 'KindInHeader' and 'KindInImplementation' fields can be set in the C/C++ tab of the Dependency Specification.
Rose RealTime generates a header (.h) file and a implementation (.c/cpp) file for each class. The 'KindInHeader' field specifies the representation of the dependency in the .h file of the client class, that is it describes how TargetClass is referenced in SourceClass' .h file. The 'KindInImplementation' field specifies the representation of the dependency in the .c/cpp file of the client class, that is it describes how TargetClass is referenced in SourceClass' .c/cpp file.
Rose RealTime's Online Help lists three options for KindInHeader and KindInImplementation, see
C++ Reference > Model Properties Reference > C++ Model Element Properties > KindInHeader (Uses, C++)
C++ Reference > Model Properties Reference > C++ Model Element Properties > KindInImplementation (Uses, C++)
- Inclusion: include the header file for the target class
- Forward reference: declare a forward reference to the target class
- None: dependency is not generated in header
When setting KindInHeader or KindInImplementation to "forward reference", the generated code in SourceClass' .h file or .c/cpp file, respectively, will contain a forward reference similar to:
class TargetClass;
When setting KindInHeader or KindInImplementation to "inclusion", the generated code in SourceClass' .h file or .c/cpp file, respectively, will contain an include statement similar to:
#include <TargetClass.h>
Depending on how TargetClass is used, the KindInHeader and KindInImplementation fields will need to be set appropriately. Generally, this is a C++ issue - if C++ accepts a forward reference, then KindInHeader can be set as "forward reference" with KindInImplementation set to "inclusion", if C++ requires a full definition, then KindInHeader needs to be set as "inclusion" with KindInImplementation set to "none".
Note: When setting KindInHeader == inclusion, it is recommended to set KindInImplementation == none. If both fields are set to "inclusion", the generated code becomes needlessly larger, causing more file open operations, more preprocessing, and longer compilation, therefore, increasing build time.
Usage Examples
If SourceClass contains a pointer to a TargetClass, or if TargetClass is only an argument of a function call, then setting the KindInHeader == forward reference, and KindInImplementation == inclusion, is sufficient.
But, if TargetClass is an attribute of SourceClass, the compiler will need the full definition of the TargetClass, and setting KindInHeader == inclusion, and KindInImplementation == none, is required.
Example 1:
class SourceClass
{
TargetClass *pTargetClass;
};
In Example 1, we need to forward reference TargetClass before defining SourceClass, therefore, KindInHeader should be set to "forward reference" with KindInImplementation == inclusion. The C++ compiler will be satisfied with KindInHeader == forward reference, because SourceClass only contains a pointer to TargetClass.
Example 2:
class SourceClass
{
TargetClass targetClass;
};
In Example 2, the C++ compiler will not accept KindInHeader == forward reference, because it needs to know the exact size of TargetClass before defining SourceClass (since SourceClass contains an instance of TargetClass). Therefore, KindInHeader needs to be set to "inclusion" with KindInImplementation == none, because SourceClass needs the full definition of TargetClass.
Note: Currently, in Rose RealTime, the defaults for new dependencies are KindInHeader == forward reference, and KindInImplementation == inclusion. These defaults can be changed in the Options dialog: Tools > Options > C or C++ tab, and select "Dependency" from the "Type" drop down list.
Related Information
Historical Number
25109
Was this topic helpful?
Document Information
More support for:
Rational Rose RealTime
Software version:
2002, 2003
Document number:
326159
Modified date:
16 June 2018
UID
swg21127917