I have a class Cache which has a function write specified as
bool write(const MemoryAccess &memory_access, CacheLine &cl);
I am calling this function like this.
const Cache *this_cache;
c = (a==b)?my_cache:not_cache;
c->write(memory_access,cl);
The above line is giving me following error
“passing ‘const Cache’ as ‘this’ argument of ‘bool Cache::write(const
MemoryAccess&, CacheLine&)’ discards qualifiers [-fpermissive].”
the this argument is compiler specific which helps in code-mangling and breaking local namespace variable priority. But such a variable is not being passed here.
Since
cis of typeconst Cache *, you can only callconstmember functions on it.You have two options:
(1) remove
constfrom the declaration ofc;(2) change
Cache::write()like so:(Note the added
constat the end.)