CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Location
    Austria
    Posts
    43

    Question COM: release-function

    Hello everybody!

    I've just tried to do my first steps under COM and by doing that I've also read about the release()-function! And following this there was some sample-code in my book:

    DWORD CSpaceship::XMotion::Release()
    {
    METHOD_PROLOGUE(CSpaceship,Motion)
    if (pThis->m_dwRef == 0)
    return 0;
    if (-pThis->m_dwRef == 0) {
    delete pThis;
    return 0;
    }

    return pthis->m_dwRef;
    }


    And I didn't understand the second if-construct with the minus in front of the pThis!
    Can anyone tell, what this minus in this case does and whats the difference between the two if-constructs?

    Thanks for helping me!

    Bye, Zechasso

  2. #2
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    The second if must must read --pThis->m_dwRef
    (two minus signs) thus decrementing the ref-counter!
    Once the references are down to zero, the object is deleted!
    The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.

  3. #3
    Join Date
    May 2003
    Location
    Austria
    Posts
    43

    Thumbs up thank you

    Just at this minute I've thought the same!
    But thank for your help!

    Ciao, Zechasso

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured