A C++ class without virtual functions can be mapped to a corresponding C structure, but there are fundamental differences between both data types. The C++ class contains data members and member functions to access and manipulate these data members. The corresponding C structure contains only the data members, but not the member functions contained in the C++ class.
Figure 202 shows the C++ class Class1 and Figure 203 shows the corresponding C structure.
Figure 202. Example of C++ Class without Virtual Functions
|
Figure 203. Example of C Structure that Corresponds to C++ Class without Virtual Functions
|
To access a C++ class from a C program you need to write your own functions to inspect and manipulate the class data members directly.
You can use C++ operators on this class if you supply your own definitions of these operators in the form of member functions.
When you write your own C++ classes that you want to access from other languages:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.