Wrapping Code with #ifdef-#endif Wrapping Code with #ifdef-#endif If you need to wrap an operation with an #ifdef #endif pair, add a compiler-specific keyword, or add a #pragma directive, you can set the SpecificationProlog , SpecificationEpilog , ImplementationProlog , and ImplementationEpilog properties for the operation. For example, to specify that an operation is available only when the code is compiled with _DEBUG : Љ Set SpecificationProlog to #ifdef _DEBUG . Љ Set SpecificationEpilog to #endif . Љ Set ImplementationProlog to #ifdef _DEBUG . Љ Set ImplementationEpilog to #endif . The same properties are available for configurations, packages, classes, and attributes.
For detailed definitions of these properties, see the property definitions displayed in the Features window. Overloading Operators You can overload operators for classes created in Rational Rhapsody. For example, for a Stack class, you can overload the “+” operator to automatically perform a push() operation, and the “-” operator to automatically perform a pop() operation. All of the overloaded operators (such as operator+ and operator- ) can be modeled as member functions, except for the stream output operator , which is a global function rather than a member function and must be declared a friend function.
The overloaded operators that are class members are all defined as primitive operations. To illustrate operator overloading, consider two classes, Complex and MainClass , defined as follows: Class Complex Attributes: double imag; double real; Operations: Complex() // Simple constructor Body: { real = imag = 0.0; } Complex(const Complex& c) //Copy constructor Arguments: const Complex& c Body: { Rational Rhapsody 949