Working with interfaces
<p>I have functions of the following form in the code I'm refactoring:</p>

<pre><code>A f()
{
    if(existing)
        return A();
    else
        return A(handle);
}
</code></pre>

<p>The Safe Bool Idiom is later used to test if A is associated with a handle or not, i.e. if we should call the class methods for this object which require internally a valid handle for execution. A's methods are const.</p>

<p>I'd like to return an interface, IA, here instead. Must I therefore return a pointer? If so I will go with boost shared pointers. I can test if the pointer is pointing to something or not.</p>

<p>Is there any way for me to work with references here instead? Would you recommend such an approach or do you think that boost::shared_ptrs is the way to go?</p>

<p><strong>UPDATE</strong></p>

<p>A is derived from IA.</p>

<p>My compiler is gcc version 4.4.3.</p>

<p>My biggest problem with this code is that A is used to interact with an external C API. Therefore I wish to mock it away using the IA interface as base for my Mock of A and its implementation, A. Then outside of the method f() above, which I see as a factory, I will only work with IA pointers. Dependency Injection in other words.</p>

<p>So A is basically a handle and an interface to a set of C API functions which require a handle. I can have several objects of type A where the interface is the same but the handle is different. </p>
