4 Answers
4

Generally, you are allowed to implicitly make things "more constant" but not "less constant" in C and C++. Therefore, you are allowed to pass a non-const object to a function that takes a const object.

Basically the const parameter in the method declaration is the function's way of promising not to modify the parameter.

What I found strange was that I received this error message in a more complex function. Although also that function was not manipulating the array the compiler send this error, in contrast to the simple example. Therefore I was wondering which criteria the compiler is using.
–
pawel_winzigOct 25 '11 at 15:30

What error were you getting specifically?
–
Jack EdmondsOct 25 '11 at 15:36

You have to be able to initialize a const data type. It's fine to pass a double* to a parameter that is const double*. That way you can do what you need to in the caller, but the callee is not allowed to change things you've said are const.

The double * to const double * conversion as a parameter type is valid, as you have had many answers that tell you that.

However, there is a strange pitfall which you may have seen before that doesn't compile which might be the cause for your confusion now. If you haven't seen code similar that doesn't compile you may want to skip this answer because it might confuse you more than help. I'm only adding the extra detail in case you thought you saw this not working before.

Sometimes the const property can be violated from pasting a const type back to the CALLER via a const type parameter pointer which has less constness in the CALLER. That does cause a compile error which at first glance appears like the same kind of conversion you made. For example, if you had void bar(const double **a) function and called it with foo(&a) in your main you WOULD get a compile error even though it seems like another situation where it only appears you are making a type more constant.