且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c ++类及其成员函数的名称调整?

更新时间:2023-01-27 10:55:32

我认为***的方法是在C ++库的周围提供C包装。这是非常受欢迎的10年或更多年前,当我在C ++编程,但我不知道是否做了任何更多。

I think the best way to do this is to provide C wrappers around the C++ library. This was quite popular 10 or more years back when I was programming in C++ but I don't know if it is done any more.

基本上,对于每个 class C ,为每个构造函数 ctor 暴露创建 externCCPtr cCtor ...)方法返回一个不透明的指针 CPtr 和每个函数 func 被暴露你创建 externCcFunc(CPtr,....)

Basically, for every class C, for every constructor ctor to be exposed to create an extern "C" CPtr cCtor(....) method that returns an opaque pointer CPtr and for every function func to be exposed you create extern "C" cFunc(CPtr,....)

另一种方法是创建具有函数指针类型的成员变量的 CStruct ,实现它们来调用类方法,让客户端做所有的努力。

Another approach is to create a CStruct that has member variables of function pointer types, implement them to call the class methods and let the client do all the hard work.