I have a library Cwith this API:
extern "C" {
typedef struct Opaque Opaque;
Opaque *foo_new();
void foo_delete(Opaque *);
int foo_f(Opaque *, int);
}
To make it easier to use, I wrap it this way:
class Foo final {
public:
Foo() { self_ = foo_new(); }
~Foo() { foo_delete(self_); }
int f(int a) { return foo_f(self_, a); }
private:
Opaque *self_;
};
Everything is fine, but then I need to wrap an array of these opaque objects:
extern "C" {
typedef struct OpaqueArray OpaqueArray;
OpaqueArray *calc_foo_array();
void foo_array_delete(OpaqueArray *);
Opaque *foo_array_elem(OpaqueArray *, size_t i);
}
Therefore, I need to implement class FooArray:
class FooArray final {
public:
??? operator[](const size_t i) {
auto obj = foo_array_elem(self_, i);
???
}
private:
OpaqueArray *self_;
};
But what should I return as a result operator[]?
Foo Opaque *, Foo::~Foo() ,
. FooRef, , Foo,
foo_delete, C classes,
.
, - reinterpret_cast - sizeof(Foo) = sizeof(Opaque *) Foo & operator[], Foo & Opaque **,
- Opaque, .
, - ?