为什么将“float **”转换为“const float **”时出现错误? [英] Why am I getting an error converting a ‘float**’ to ‘const float**’?

查看:1443
本文介绍了为什么将“float **”转换为“const float **”时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数接收 float ** 作为参数,我试图改变它采取 const float **

I have a function that receives float** as an argument, and I tried to change it to take const float**.

编译器( g ++ )不喜欢它并发出:

The compiler (g++) didn't like it and issued :

从float **到const float **的无效转换

这对我没有意义,我知道(和验证),我可以传递 char * 到一个函数 const char * ,为什么不用 const float **

this makes no sense to me, I know (and verified) that I can pass char* to a function that takes const char*, so why not with const float**?

推荐答案

See Why am I getting an error converting a Foo** → const Foo**?


因为转换 Foo ** const Foo ** 将无效和危险...转换从 Foo ** const Foo ** 是危险的,它会让你静默和不小心修改一个const Foo对象没有转换

Because converting Foo**const Foo** would be invalid and dangerous ... The reason the conversion from Foo**const Foo** is dangerous is that it would let you silently and accidentally modify a const Foo object without a cast

引用继续给出一个隐式转换如何允许我修改 const 对象没有转换的例子。

The reference goes on to give an example of how such an implicit conversion could allow me one to modify a const object without a cast.

这篇关于为什么将“float **”转换为“const float **”时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆