search

Home  >  Q&A  >  body text

c++ - 为什么<<操作符重载的时候第二个参数必须是const?

的确,输出函数不需要改变对象的值,应该声明为const,但是不声明为const应该也是允许的,为什么不能通过编译呢?

迷茫迷茫2803 days ago668

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:13:25

    A parameter is declared as const, which means that changes are not allowed within the function, and constants and variables can be manipulated. On the contrary, not declaring it as const means that changes are allowed and only variables can be manipulated, not constants. In other words, const formal parameters can correspond to const and non-const actual parameters, but not vice versa.

    reply
    0
  • Cancelreply