what does ~ mean before a function in C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • QQ

    #1

    what does ~ mean before a function in C++

    for example
    ~CcMessage() {}

    Thanks a lot!

    I am a beginner for C++, so please forgive my stupid questions

  • Marcin Kalicinski

    #2
    Re: what does ~ mean before a function in C++

    > for example[color=blue]
    > ~CcMessage() {}[/color]

    It means that it is a destructor for class CcMessage.

    cheers,
    M.


    Comment

    • Samee Zahur

      #3
      Re: what does ~ mean before a function in C++

      Since you say you are a beginner, I can't tell if you know what a class
      means - if you do, a function like that inside a class named CcMessage
      gets called each time an object of that class goes out of scope - it
      performs certain cleanups needed to destroy the object.

      Samee

      Comment

      • Mike Wahler

        #4
        Re: what does ~ mean before a function in C++


        "QQ" <junciu@yahoo.c om> wrote in message
        news:1115228501 .029669.103590@ z14g2000cwz.goo glegroups.com.. .[color=blue]
        > for example
        > ~CcMessage() {}[/color]

        It's a destructor. Look it up.
        [color=blue]
        > Thanks a lot!
        >
        > I am a beginner for C++, so please forgive my stupid questions[/color]

        No need to 'forgive' you, only to recommend you
        get a good textbook or two about C++. It's virtually
        impossible to learn it without one.

        For peer reviews see www.accu.org

        -Mike


        Comment

        • Tim Slattery

          #5
          Re: what does ~ mean before a function in C++

          "QQ" <junciu@yahoo.c om> wrote:
          [color=blue]
          >for example
          > ~CcMessage() {}[/color]

          It means that this is the destructor function for class CcMessage. It
          will be called when an object of class CcMessage is destroyed.

          --
          Tim Slattery
          Slattery_T@bls. gov

          Comment

          Working...