从Foo **到void **的转换无效 - 为什么隐式类型转换允许void *,而不是void **? [英] 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; //无效的转换
据我所知,指向任何非指针类型的指针可以是隐式的在C ++中转换为 void *
。为什么同样不允许为 void ** ?
指定类型的指针类型
指针可以隐式转换为 void *
,因为 void *
是通用指针。然而, void **
不是指针的通用指针。
C FAQ 4.9 解释了为什么在C中没有指向指针类型的通用指针,我认为它也适用于C ++。 p>
struct Foo {};
...
void * p = (Foo*)0; // OK
void ** pp = (Foo**)0; // Invalid conversion
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**
?
解决方案
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 explains why there is no generic pointer to pointer type in C, I think it applies to C++ as well.
这篇关于从Foo **到void **的转换无效 - 为什么隐式类型转换允许void *,而不是void **?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文