Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gcc 通过‘;const此参数丢弃限定符[-fppermissive]_Gcc_G++ - Fatal编程技术网

Gcc 通过‘;const此参数丢弃限定符[-fppermissive]

Gcc 通过‘;const此参数丢弃限定符[-fppermissive],gcc,g++,Gcc,G++,我有一个类缓存,它的函数write指定为 bool write(const MemoryAccess &memory_access, CacheLine &cl); 我这样调用这个函数 const Cache *this_cache; c = (a==b)?my_cache:not_cache; c->write(memory_access,cl); 上面这行给了我以下的错误 将'const Cache'作为'bool Cache::write(const)的'this

我有一个类
缓存
,它的函数write指定为

bool write(const MemoryAccess &memory_access, CacheLine &cl);
我这样调用这个函数

const Cache *this_cache;
c = (a==b)?my_cache:not_cache;
c->write(memory_access,cl);
上面这行给了我以下的错误

将'const Cache'作为'bool Cache::write(const)的'this'参数传递 MemoryAccess&,CacheLine&)丢弃限定符[-fpPermissive]


此参数是特定于编译器的,它有助于代码混乱和破坏本地命名空间变量优先级。但是这样的变量没有在这里传递。

当您通过指向对象的指针调用方法时,此对象将作为
this
指针隐式传递给该方法
c
可能具有类型
const Cache*
。由于方法
write
未声明为
const
,因此它具有非const
指针,可从其主体访问该指针,需要丢弃
const
限定符
c

c
类型为
const Cache*
,因此只能调用其上的
const
成员函数

您有两个选择:

(1) 从
c
的声明中删除
const

(2) 更改缓存::write()
如下:

 bool write(const MemoryAccess &memory_access, CacheLine &cl) const;

(注意末尾添加的
const

此外,如果类的方法返回任何成员的指针,则在返回类型示例之前不应忘记写入const:


常量浮点*getPosition()常量{…}

请尝试修复您的示例:您谈论函数
写入
,然后调用
读取
。您在哪里声明
内存访问
cl
?此参数是特定于编译器的,有助于代码损坏和破坏本地命名空间变量优先级???签名末尾的常量的意义是什么??当我们说这是常数时,到底是什么意思。默认情况下,它是否不是常量???@prathesh.kallulgar: