Is it safe to return a casted reference? : <p>Let <code>Point</code> be a class whose instances can be explicitly casted to a <code>wxPoint</code>:</p>

<pre><code>class Point{
private:
    int x;
    int y;
public:
    explicit operator wxPoint() const
    {
        return wxPoint(x, y);
    }

    // More stuff
}
</code></pre>

<p>I have a function that returns a reference to an object of type <code>Point</code>. The header of such a function is:</p>

<pre><code>const Point&amp; GetPoint();
</code></pre>

<p>My question: is it safe to define the following <code>Foo</code> function?</p>

<pre><code>const wxPoint&amp; Foo() const{
    return (wxPoint&amp;) GetPoint();
}
</code></pre>

<p>First I implemented <code>Foo</code> with <code>return (wxPoint) GetPoint();</code>, but that created a new (local) object and therefore a useful warning is triggered. The code shown here compiles without warnings.</p>

<p>All the information I found on this kind of casting refers to inherited classes, which is not the case here.</p>

<p>An explanation of what is exactly going on when casting a reference in this way would be really appreciated.</p>
