class M {
public:
virtual int foo(int);
// ...
private:
int i, j;
};
在C代碼中無法聲明Class M,最好的方式是采用指針。C++代碼中聲明如下:
extern "C" int call_M_foo(M* m, int i) { return m->foo(i); }
在C代碼中,可以這樣調(diào)用:
struct M; /* you can supply only an incomplete declaration */
int call_M_foo(struct M*, int); /* declare the wrapper function */
int f(struct M* p, int j) /* now you can call M::foo */
{ return call_M_foo(p, j); }