How can I have in C++ a static method in a class and a (non-copy) constructor (const T &t) so that I can return t from the static method?
class chunk_t
{
public:
explicit chunk_t();
~chunk_t();
static chunk_t create_from(const roaring_bitmap_t &data, bool filled = false);
private:
bool filled = false;
roaring_bitmap_t *data = nullptr;
explicit chunk_t(const chunk_t &other);
};
chunk_t::chunk_t()
{
this->data = roaring_bitmap_create_with_capacity(C);
}
chunk_t::chunk_t(const chunk_t &other)
{
_ASSERT(other.data != nullptr);
this->data = roaring_bitmap_copy(other.data);
this->filled = other.filled;
}
chunk_t chunk_t::create_from(const roaring_bitmap_t &data, bool filled)
{
chunk_t c;
c.data = roaring_bitmap_copy(&data);
c.filled = filled;
return c; // ERROR: class `chunk_t` has no suitable copy constructor
}
chunk_t::~chunk_t()
{
if(this->data != nullptr)
{
roaring_bitmap_free(this->data);
this->data = nullptr;
}
}
Aucun commentaire:
Enregistrer un commentaire