不能施放数组指针 [英] Cannot cast array to pointer
本文介绍了不能施放数组指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下来源:
#include <iostream>
using namespace std;
void main(int j)
{
char arr[10][10];
char** ptr;
ptr = arr;
}
当我编译使用VS2010它,我得到这个错误:
when I compile it using VS2010 I get this error:
error : a value of type "char (*)[10]" cannot be assigned to an entity of type "char **"
我想在C ++中数组只是指针。因此,一个的char [] []
也有可能是的char **
。我在做什么错了?
I thought arrays in c++ were just pointers. So a char[][]
could also be char**
. What am I doing wrong?
推荐答案
类型的char [10] [10]
和的char **
和字符(*)[10]
都是不同的类型。然而,第一个不能转换成第二个,它的可以转换成第三个。
The types char[10][10]
and char**
and char (*)[10]
are all different types. However, the first one cannot convert into the second one, it can convert into the third one.
所以,试试这个:
char arr[10][10];
char (*ptr)[10];
ptr = arr; //ok
它会工作,因为正如我所说类型的对象的char [10] [10]
可以转换成键入字符(的对象* )[10]
。他们是兼容类型。
It will work, because as I said object of type char[10][10]
can convert into an object of type char (*)[10]
. They're compatible types.
这篇关于不能施放数组指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文