【发布时间】:2017-02-01 11:34:14
【问题描述】:
我最近尝试使用 std::unique_ptr 和自定义删除器包装 libdbus 类型和 libevent 类型以简化代码,但这些库出现错误:
/opt/cross/armv7hl-meego-linux-gnueabi/include/c++/4.8.3/bits/unique_ptr.h:65:22: error: invalid application of 'sizeof' to incomplete type 'sockets::libev::event_base'
static_assert(sizeof(_Tp)>0,
^
代码很简单:
namespace sockets {
// ... unix sockets stuff
namespace libev {
#include <event.h>
} // libev
} // sockets
class A {
public:
void run() {
using namespace sockets;
using namespace sockets::libev;
using UniqueEventBase = std::unique_ptr<event_base>;
// ...
}
};
那么在这个例子中我该如何为event_base struct 编写RAII-wrappers 呢?
附:我发现event_base 结构是在event2/event.h 中前向声明的。所以没有选项来包装它?
【问题讨论】:
标签: c++ c++11 unique-ptr libevent