error: passing 'const …' as 'this' argument of '…' discards qualifiers

后端 未结 1 1231
野的像风
野的像风 2020-12-03 01:20

error: passing \'const A\' as \'this\' argument of \'void A::hi()\' discards qualifiers [-fpermissive]

I don\'t understand why I\'m getting

相关标签:
1条回答
  • 2020-12-03 01:47

    Your hi method is not declared as const inside your A class. Hence, the compiler cannot guarantee that calling a.hi() will not change your constant reference to a, thus it raises an error.

    You can read more about constant member functions here and correct usage of the const keyword here.

    0 讨论(0)
提交回复
热议问题