I'm trying to wrap a C library which uses patterns like this:
Thing* x= new_thing_("blah");
Thing* tmp= thing_copy(x);
In c++, I'd like to be able to do something like
auto_ptr x=new CXXThing("blah");
auto_ptr tmp=new CXXThing(*x);
char* message = y->get_message();
Obviously, CXXOther wraps a pointer to a CXXThing as well. So the problem I'm encountering is that essentially I'd like to just "insert" functions and members into existing structs (I think this is known as the "Mixin" idea).
The problem is that if I include a Thing as an element of the CXXThing, then I don't know how I'd declare the constructor, and if I include a *pointer* to the wrapped class, then I have an extra level of useless indirection.
How should I wrap it so that this is possible? (An answer of "What you want to do is not best/possible... here is the proper way" is also acceptable.) I may be wrong, but I was under the impression that you might return auto_ptrs to express transferring the ownership of an object (gotw.ca/publications/using_auto_ptr_effectively.htm)
以上就是C++ wrap C struct *and* and functions的详细内容，更多请关注web前端其它相关文章！