Hi,

I am porting C++ code that undo "Object Slicing" by casting const-references:
http://en.wikipedia.org/wiki/Object_slicing


My translation in D Code
----

struct A
{
 // stuff
}

struct B
{
  A a;
  alias a this;
 // stuff
}

void myFunction(ref const(A) a)
{
    if (<a-is-actually-a-B>)
    {
        // here goes the converstion to a B reference
myFunction2(*cast(const(B)*)(&a)); // using pointer to do type-punning
    }
}

----


To do this, I need to by guaranteed an object passed through ref const(A) is never, ever passed by value. Is it safe to assume?

Reply via email to