passing ‘const this argument discards qualifiers [-fpermissive]

后端 未结 3 443
一向
一向 2020-12-29 02:03

I have a class Cache which has a function write specified as

bool write(const MemoryAccess &memory_access, CacheLine &cl);
3条回答
  •  无人及你
    2020-12-29 02:19

    When you call a method via a pointer to an object, this object is implicitly passed to the method as this pointer. c probably has type const Cache*. Since method write is not declared as const, it has non-const this pointer accessible from its body requiring const qualifier of c to be discarded.

提交回复
热议问题