HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

#include <iostream.h>
typedef class obj* obj_ptr;
extern C void initialize_obj (obj_ptr& p);
extern C void delete_obj (obj_ptr p);
extern C void print_obj (obj_ptr p);
struct obj {
private:
int x;
public:
obj() {x = 7;}
friend void print_obj(obj_ptr p);
};
// C interface routine to initialize an
// object by calling the constructor.
void initialize_obj(obj_ptr& p) {
p = new obj;
}
// C interface routine to destroy an
// object by calling the destructor.
void delete_obj(obj_ptr p) {
delete p;
}
// C interface routine to display
// manipulating the object.
void print_obj(obj_ptr p) {
cout << the value of object->x is << p->x << \n;
}
Following is a C program that calls the C++ module to manipulate an object:
/***************************************************/
/* C program to demonstrate an interface to the */
/* C++ module. Note that the application needs */
/* to be linked with the aCC driver. */
/***************************************************/
typedef struct obj* obj_ptr;
int main () {
/* C++ object. Notice that none of the
routines should try to manipulate the fields.
*/
obj_ptr f;
/* The first executable statement needs to be a call
to _main so that static objects will be created in
libraries that have constructors defined. In this
application, the stream library contains data
240 Mixing C++ with Other Languages