1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 int a[5]={0,1,2,3,4};
7 void* p=&a;
8 cout<<sizeof(*(int* [5])p)<<endl;
9 }
t1.cc: In function ‘int main()’:
t1.cc:8: error: ISO C++ forbids casting to an array type ‘int* [5]’
请问void指针为何不能转换为int *[5]的指针,谢谢了.
错误地方: void* p=&a;
改为: void* p=a;
因为a本身就是数组的首地址
不一样的
void* p=&a; 表示为类型为a[5]的地址
void* p=a; 表示为a[5]数组的a[0]的地址
2个类型不一样的
cout << sizeof(*(int (*)[])p) << endl;