The definition of the new for arrays sets a rule for indexes
noptr-new-declarator:
[ expression ] attribute-specifier-seqopt
noptr-new-declarator [ constant-expression ] attribute-specifier-seqopt
So every index except the first must be constant-expression. And the compiler says you about this rule in your first example of code
main.cpp: In member function 'void A::fun()':
main.cpp:31:39: error: 'A::y' cannot appear in a constant-expression
make[2]: Leaving directory `D:/New Folder/CppApplication_1'
main.cpp:31:42: error: 'A::z' cannot appear in a constant-expression
That is for the statement
int(*pchar)[x][y] = new int[x][y][z];
the compiler says that used in the expression A::y and A::z must be constant expression during compilation time.
In your second example you explicitly specified constants
1 2 3
|
const int x = 10;
const int y = 10;
const int z = 10;
|
So during compilation the compiler knows values of y and z. It was not nessesary to made x also constant, because you can specify any non negative value for the first index in runtime (including zero).