Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting an error converting a ‘float**’ to ‘const float**’?

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

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

invalid conversion from ‘float**’ to ‘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**?

like image 477
Omry Yadan Avatar asked Mar 17 '10 15:03

Omry Yadan


1 Answers

See Why am I getting an error converting a 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

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.

like image 180
Sean Avatar answered Sep 20 '22 03:09

Sean