Cocreate an Object with a Smart Pointer Reference


A class is often cocreated at the same time that a smart pointer is declared:
[C++]
IFooPtr ipFoo(CLSID_Foo);
For the sake of simplicity, the code snippets given don't always check HRESULT's, although as a developer you should always do so.
However, in certain cases, it may be necessary for you to declare the smart pointer first and cocreate the class later. This can be accomplished in the manner below. Notice the use of the `dot' member selection operator, as opposed to the arrow member selection operator that is usually used with smart pointer types:
[C++]
IFooPtr ipFoo;
// more code would be here
ipFoo.CreateInstance(CLSID_Foo);