Relation Between a C++ Class and C structure

Hi,

Can someone give me idea how we can use the C++ class in C language.

Will it be possible to assign a structure pointer in C to the class pointer in C++. The language that to be used is C.

in C++
------

class M{
.....
.....
public:
int foo();
};

//wrapper in C++ for accessing the foo() member in C.

extern "C" int call_foo_M(M * m){
std::cout<<"HELLO WORLD";
}

//Compiling the above programme in C++.

--------------------------------------------------------------------------------

in C
----

struct M;
call_foo_M(struct M *); //will it work

--------------------------------------------------------------------------------

Will the above code work ok?
Is it possible to derive a class from a structure developed in C?

Can anyone give me the correct files name including for the headers that to be used?

If possible please give the proper solution....


Thanks and Regards,
Nandu Mishra




If I understand you correctly, you want to use a C++ class from C. The short answer is, you shouldn't.

C++ is largely a superset of C, and a class is notion that exists in C++ but not C. If your class does not use inheritance or virtual, the class will have the same layout as the equivalent C structure. But different compilers may use different packing.
Topic archived. No new replies allowed.