Returning a reference to *this, from an anonymous object on stack
<p>Suppose the class <code>Coord3D</code> has a method </p>

<pre><code>Point2D&amp; Coord3D::get2DPart(){
    return *(Point2D*)this;
}
</code></pre>

<p>(Coord3D is just int x; int y; int z;, and Point2D is the 2D version of it with exactly int x; and int y;)</p>

<p>Would the following be safe:</p>

<pre><code>Point2D x = Coord3D(1,2,3).get2DPart();
</code></pre>

<p>Or even something like</p>

<pre><code>Coord3D x = Coord3D(1,2,3).getSelf();
</code></pre>

<p>where <code>getSelf()</code> is a function which does <code>return *this;</code></p>

<p>Seems like it'll probably be safe, but people I asked aren't sure about it. Is this OK?</p>

<p><strong>Edit:</strong> this is what coord3D and Point2D are:</p>

<pre><code>struct Coord3D{
   float x; float y; float z;
};
struct Point2D{
   float x; float y;
};
</code></pre>
