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

前端 未结 6 2217
孤街浪徒
孤街浪徒 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:54

    As others have noted, in the instance you are asking about it is the destructor for class Stack.

    But taking your question exactly as it appears in the title:

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

    there is another situation. In any context except immediately before the name of a class (which is the destructor context), ~ is the one's complement (or bitwise not) operator. To be sure it does not come up very often, but you can imagine a case like

    if (~getMask()) { ...
    

    which looks similar, but has a very different meaning.

提交回复
热议问题