Invalid conversion from Foo** to void** - why is implicit type conversion allowed to void* but not to void**?(从 Foo** 到 void** 的无效转换 - 为什么允许隐式类型转换为 void* 但不允许为 void**?)
问题描述
struct Foo {};
...
void * p = (Foo*)0; // OK
void ** pp = (Foo**)0; // Invalid conversion
据我所知,指向任何非指针类型的指针都可以在 C++ 中隐式转换为 void*
.那么为什么不允许将指针类型转换为 void**
?
As far as I recall, a pointer to any non-pointer type can be implicitly cast to void*
in C++. Why then is the same not allowed for casting a ponter to pointer type to void**
?
推荐答案
指针可以隐式转换为 void *
因为 void *
是通用指针.但是,void **
不是指向指针的通用指针.
A pointer can be implicitly cast to void *
because void *
is the generic pointer. However, void **
isn't the generic pointer to pointer.
C FAQ 4.9 解释了为什么 C 中没有指向指针类型的通用指针,我认为它也适用于 C++.
C FAQ 4.9 explains why there is no generic pointer to pointer type in C, I think it applies to C++ as well.
这篇关于从 Foo** 到 void** 的无效转换 - 为什么允许隐式类型转换为 void* 但不允许为 void**?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Foo** 到 void** 的无效转换 - 为什么允许隐式类型转换为 void* 但不允许为 void**?


- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01