What actually fails is the initialization of 'a'.
Add another
this(A a) { /* Stuff */ }
constructor to the 'A' struct, and it will work.
And, yes, the missing cpctors are a language problem.
artur
Thanks. Yeah, I figured I could do that, I was just hoping that I
could leverage the po
On 05/03/14 01:05, Mark Isaacson via Digitalmars-d-learn wrote:
> 2) I ran into this issue while attempting to leverage the postblit for
> code-reuse. In particular, I have a setup that is similar to:
>
> struct A {
> this(B b) { /* Stuff */ }
> }
>
> struct B {
> }
>
> void foo(T)(T param) {
@bearophile - Unless I'm missing something, alas, no. Neither A
nor B is a subtype of the other. In particular, in the real code
one is a CartesianVector and the other a PolarVector. For what
it's worth, 'foo' is actually opBinary addition.
Thanks for the thought though.
Mark Isaacson:
Accordingly, I no longer need an answer to my second question
unless someone knows of a more idiomatic way to get the same
results.
Is the "alias this" useful in this case?
Bye,
bearophile
Did some thinking: Realized that the appropriate mechanism to
express that A and B are two ways of representing the same thing
is to do so via opCast. I had not considered this option
carefully initially as I am translating someone else's C++ code
to D and hoped that they had used the appropria
I have just discovered that the postblit constructor is not able
to be invoked like a "normal" constructor, or, as one would
manually do so in C++ with a copy constructor. Accordingly I have
a couple questions:
1) What are the various ways to invoke the postblit constructor?
I have not tested