In c++ what does a tilde “~” before a function name signify?

前端 未结 6 2215
孤街浪徒
孤街浪徒 2020-12-04 07:24
 template 
 class Stack
 {
 public:
    Stack(int = 10) ; 
    ~Stack() { delete [] stackPtr ; }  //<--- What does the \"~\" signify?
    int push(         


        
6条回答
  •  借酒劲吻你
    2020-12-04 07:59

    This is a destructor. It's called when the object is destroyed (out of life scope or deleted).

    To be clear, you have to use ~NameOfTheClass like for the constructor, other names are invalid.

提交回复
热议问题