A library which I can't modify has a type akin to the following:
class A {
public:
A () : A(0) { }
explicit A (int const value) : value_(value) { }
A (A const &) = delete;
A (A &&) = delete;
A & operator= (A const &) = delete;
A & operator= (A &&) = delete;
private:
int value_;
}
Now, I have a class which requires a bunch of A
s as members. The most logical way to structure them is by putting them in an array. E.g. something like :
struct Foo {
A a[2];
}
Is there any way to initialize each member with a distinct initial value? I've been trying various forms of using braced-list initialization, but they all fail due to either A(int)
being explicit or A
not having a copy/move-constructor.
What doesn't work:
Foo () : A{ { 1 }, { 2 } } { }
: won't callA(int)
since it'sexplicit
.Foo () : A{ { A(1) }, { A(2) } } { }
: can't copy- nor move-assign.
Aucun commentaire:
Enregistrer un commentaire