C++ wrap C struct *and* and functions

I'm trying to wrap a C library which uses patterns like this: Thing* x= new_thing_("blah"); Thing* tmp= thing_copy(x); free_thing(tmp); Other* y=get_other(x,7); char* message=get_message(x,y); free_thing(x); free_other(y); In c++, I'd like to be able to do something like auto_ptr x=new CXXThing("blah"); auto_ptr tmp=new CXXThing(*x); auto_ptr y=x->get_other(7); 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准