clang ++ 2d数组指针奇怪的错误

时间:2015-03-06 20:12:42

标签: c++ c++11 lvalue rvalue

以下代码使用g ++编译良好,但在c ++ 11模式下使用clang ++失败。我已经注意到内联错误。有人可以准确解释问题是什么吗?

#include <iostream>
using namespace std;
int main(){
    int nx=1000;
    int ny=1000;
    double *p=new double[nx*ny];
    auto pp=(double (*)[nx])p;//fine
    auto pp2=(double (*)[nx])p;//fine
    pp=pp2;  //error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
    decltype(pp2) pp3=pp2;//fine
    double (*pp4)[nx]=(double(*)[nx])p;//error: cannot initialize a variable of type 'double (*)[nx]' with an rvalue of type 'double (*)[nx]'
    double (*pp5)[nx]=pp;//error: cannot initialize a variable of type 'double (*)[nx]' with an lvalue of type 'double (*)[nx]'
    pp=pp2;//error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
    pp=(double(*)[nx])p;//error: assigning to 'double (*)[nx]' from incompatible type 'double (*)[nx]'
    pp[1][0]=1;
    cout << pp2[1][0]<< endl;
}

0 个答案:

没有答案