传递 'const 这个参数会丢弃限定符 [-fpermissive] [英] passing ‘const this argument discards qualifiers [-fpermissive]
本文介绍了传递 'const 这个参数会丢弃限定符 [-fpermissive]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 c
is of type const Cache *
, you can only call const
member functions on it.
You have two options:
(1) remove const
from the declaration of c
;
(2) change Cache::write()
like so:
bool write(const MemoryAccess &memory_access, CacheLine &cl) const;
(Note the added const
at the end.)
这篇关于传递 'const 这个参数会丢弃限定符 [-fpermissive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文