c++ - Release Interface pointers -


I, in some smart signal class desiccator, have declared the member variable within a class to free this interface The code, which is better, is:

Members varible

  CComQIPtr & lt; IMyInterFace & gt; m_pMyInterface;   

constructor

  m_pMyInterface.CreateInstace (CLSID_MyInterface); Destructive in   

  if (m_pMyInterface) m_pMyInterface.Release ();   

Or should it be

  if (m_pMyInterface.p = zero!) M_pMyInterface.Release ();   

The above form which is a better one and the way I am using interface pointsers there is a flaw. Tom

~ CComQIPtr The Destructor takes care of everyone to explicitly release you There is no need to do so, if you want, to reuse the variable, you can do either of the two:

  • m_pMyInterface.Release ();
  • m_pMyInterface = Zero;

    With zero (operator = CComPtr , with CComQIPtr may be unclear) Works) check is not required, the CComQIPtr :: release method does this anyway.

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -