C++ C/C++;使人感到奇怪

C++ C/C++;使人感到奇怪,c++,c,casting,constants,C++,C,Casting,Constants,我有一个函数声明为: int myFunction(const float** ppArr, const int n, const int m); 当我这样称呼它时: float** ppArr = new float*[5]; // Some initialization of ppArr int result = myFunction(ppArr, 5, 128); <<<< Error WTF?我正在将一个浮点数**转换为常量浮点数**。这可能会出什么问题/

我有一个函数声明为:

int myFunction(const float** ppArr, const int n, const int m);
当我这样称呼它时:

float** ppArr = new float*[5];
// Some initialization of ppArr

int result = myFunction(ppArr, 5, 128);  <<<< Error
WTF?我正在将一个浮点数**转换为常量浮点数**。这可能会出什么问题/


编辑:感谢您的快速回复!!!:)

尽管看起来很奇怪,但在某些模糊的情况下,它实际上会降低常量的正确性,从而允许您间接修改常量对象

有关详细信息,请参阅


< >您可以将<代码> Fo**>代码>转换为<代码> Fo-const *const */COD>这不会留下任何后门打开。

< P>请在C++ FAQ中阅读。

<代码>浮点**/COD>不能转换为<代码> const浮点**/COD> < < /P> 它可以转换为
float*const*
const float*const*
。像这样:

void f(float* const* p) {}

void h(const float* const* p) {}

int main() {
    float** p= new float*[5];
    f(p);
    h(p);
}

<>编译GCC:

< P>只是在最有效的答案中加上一个重要的观察:C和C++的情况不同。而技巧在C++中使用<代码> fo const *const */COD>这在C中不起作用,它不接受这个并发出警告。
在C语言中,如果你想将typesafe转换为
Foo-const*const*

@David:另一个答案解释了这一点。我只是懒惰:Pi找不到一个理由,为什么C(甚至C11),而不是C++,不允许“代码> Foo**<代码>的隐式转换为<代码> FO const *const */COD>。你知道吗?我模糊地记得,委员会认为强制执行这样的规则对于直接的编译器实现来说太复杂了。(好吧,这样的野兽曾经存在过吗?)无论如何,这在C语言中是一个真正的限制,使得使用
const
对于多维函数参数几乎不切实际。这让我想哭。这是一个真实的、客观的缺陷。我从来没有写过编译器,但我不知道允许添加任意长度的隐式添加的
常量的链有多复杂,而不是只添加长度
void f(float* const* p) {}

void h(const float* const* p) {}

int main() {
    float** p= new float*[5];
    f(p);
    h(p);
}