Discards qualifiers error

前端 未结 4 657
臣服心动
臣服心动 2020-11-29 11:09

For my compsci class, I am implementing a Stack template class, but have run into an odd error:

Stack.h: In member function ‘const T Stack

4条回答
  •  情书的邮戳
    2020-11-29 11:55

    You cannot call a non-const method from a const method. That would 'discard' the const qualifier.

    Basically it means that if it allowed you to call the method, then it could change the object, and that would break the promise of not modifying the object that the const at the end of the method signature offers.

提交回复
热议问题