Topic: Xmotif in C++ environment


Author: cics01@ccsun.strath.ac.uk ("L.Jinsang")
Date: 23 Nov 1993 20:20:34 GMT
Raw View
Hello,

Please forgive my ignorance if this is a general question.

For last one year, I developed a interface system using xmotif
with c on sun4.

Now, I want to combine a module which use c++ with the original interface
system.  This module works fine with a c++ compiler. I tried to combine
these two program by calling the c++ module from the xmotif(c) main
interface but failed. Somebody told me it is possible to use c in c++
environment but not for c++ in c environment.

In Douglus Young's book, he uses c++ environment & has a c++ xmotif
library which have all c++ motif functions matches with normal c motif functions.
Which is opposite case of mine. Am I wrong?

Following is my questions, please help:

1. I want to keep my original c code for the main interface (although minor
changes would be ok). Is it possible to have c++ modules in the c environment?
2. If '1' is impossible, I want to have simple c++ main code
which calls my main interface system(c code)  as a function or
whatever, and then use c++ module in the interface system.  But I
don't know how to do it. I am sure c++ compiler doesn`t recognize the
motif functions.


Thanks in advance.

Inhan




Author: cbrooks@afit.af.mil (Christopher L Brooks)
Date: Wed, 24 Nov 1993 12:11:28 GMT
Raw View
You will have to use a set of wrappers around your C++
code for it to work.  Since C has no concept of objects,
you need to create functions that create and destroy your
objects.  For example:

class A {
public:
    A(int a);
    void Foo(void);
}

You could have a global pointer to an A in your C++
file:

A *an_a_pointer;

And write a function like this:

extern "C" {
    void InitA(int a);
    void AFoo();
    void DeleteA();
}

void InitA(int a)
{
    A = new A(a);
}

And so on.  Send e-mail if you need any more details.
Of course there are other options for doing this; this
is just one way.

--
Chris Brooks
cbrooks@afit.af.mil