ITPub博客

首页 > > > int[][] 强转成int**,运行时出错???

int[][] 强转成int**,运行时出错???

作者:chinarocky 时间:2019-09-04 15:11:21 0 删除 编辑
void f(int **a)
{
    cout << a[0][0] << endl;
    cout << a[1][0] << endl;
}

int main() 
{ 
    {
        int t1[2];
        int tt[2][2];
        tt[0][0] = 1;
        tt[0][1] = 2;
        tt[1][0] = 3;
        tt[1][1] = 4;
        int **ttp = new int*[2];
        for(int i = 0; i < 2; ++i)
        {
            ttp[i] = new int[2];
            for(int j = 0; j < 2; ++j)
            {
                ttp[i][j] = tt[i][j];
            }
        }
        
       // 此处强转,在f中访问[0][0]元素时会出错。
       // 传入ttp则是好的。 
       // 错误提示:test.exe 中的 0x00ee17bd 处有未经处理的异常: 0xC0000005: 读取位置 0x00000001 时发生访问冲突
       f((int**)tt); 
    }
    return 0;


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4547/viewspace-3122131/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: flask 部署
请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    213
  • 访问量
    1690