> No, no, no. That's not what I was saying at all. What I meant was
> this:
>
> class COMInit
> {
> ...
> }
>
> int main()
> {
>   COMInit comInit;
>   CComPtr< IX > pX;
>   pX.CoCreateInstance( CLSID_X );
>  }

Aha.  This works well, but it creates a maintenance issue, because comInit
must be declared before the other local CComPtr's, and remembering this can be
difficult, whereas with a global, comInit will be constructed before main( )
and will be destroyed after it.

> The thing I was complaining about was you global instance of COMInit.
>
> It's unnecessary and globals are evil. :-)

I know what you're saying, but I think it's more a matter of taste than a
technical issue.  What hurt could it make to have a .cpp file containing this:

 // COMInit.cpp

 namespace
 {
  class CComInit
  {
   // ...
  } const g_comInit;
 }

Even the global doesn't pollute the global namespace as far as the rest of the
source files are concerned.

-------------
Ehsan Akhgari

Farda Technology (www.farda-tech.com)

List Owner: [EMAIL PROTECTED]

[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]

It is dreadful to die of thirst in the sea. Do you have to salt your truth so
much that it can no longer even - quench thirst?
-Beyond Good And Evil, F. W. Nietzsche





Reply via email to