Consider:
struct A {
A (int);
A (const A &);
};
struct B {
A foo [2];
B (const A & x, const A & y)
: foo {x, y} /* HERE IS THE PROBLEM */
{}
};
I was expecting this to work since I'm using C++0x support in GCC4.3, which allegedly supports initialiser lists. No joy.
I have a class A which has no default constructor. This is not negotiable. Assignment post-default is not an option.
I am trying to create B which uses A. B::foo may not be std::vector.
How can I initialise B::foo
in B(...)
, constructing its elements exactly once?
At the moment, I am condidering replacing B with
struct B {
A foo_a;
B foo_b;
A * foo () {
assert ((&foo_b) - *&foo_a) == 1);
return &foo_a;
}
B (const A & x, const A & y) : foo_a(x), foo_b(y) {}
};
Or even using char foo [2*sizeof(A)]
with placement new -- YUK!
Surely there's a proper way to do this !?!?!
Thanks for your help