Keywords: classdesc

Next: Parameter passing between C++ Up: C++ model Objective-C design Previous: File conventions used Contents Index

### Objects creation in the C++ and Objective-C environments

Figure 5 shows an example of a C++ model and Figure 6 shows the equivalent Objective-C object template. Since Objective-C and C++ programs are both run in the same memory space, only one copy of the object is created and shared between both environments.

In our implementation, shared Objective-C/C++ objects are instantiated in the Objective-C environment (since all the objects in Objective-C environment must be inherited from the Objective-C base class for them to behave as Objective-C objects) and are accessed in the C++ environment using the objects' C++ class templates (the Objective-C objects' pointers are passed to the C++ environment for typecasting).

Figure 5: An example of a user C++ model (myCounter.h)

Figure 6: An equivalent Objective-C object template (myCounter.mh)