c++ - 为什么<<操作符重载的时候第二个参数必须是const?
迷茫
迷茫 2017-04-17 13:11:25
0
1
611

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
Ty80

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!