据我了解,const
修饰语应从右至左阅读。从中我得到:
const char*
是一个指针,其char元素不能被修改,但是指针本身可以被修改,并且
char const*
是mutable
char的常量指针。
但是,以下代码出现以下错误:
const char* x = new char[20];
x = new char[30]; //this works, as expected
x[0] = 'a'; //gives an error as expected
char const* y = new char[20];
y = new char[20]; //this works, although the pointer should be const (right?)
y[0] = 'a'; //this doesn't although I expect it to work
那么是哪一个呢?我的理解还是我的编译器(VS 2005)错误?