如果我已将结构的成员复制到我的班级,我是否可以从班级转换为结构?
#include <stdint.h>
#include <sys/uio.h>
class Buffer
{
public:
void * address;
size_t size;
Buffer(void * address = nullptr, size_t size = 0)
: address(address), size(size)
{
}
operator iovec *() const
{
// Cast this to iovec. Should work because of standard layout?
return reinterpret_cast<iovec *>(this);
}
}