标签:out eve ons void his const reverse main this
class Same { public: void reverse(const char* str) { char* A = const_cast<char*>(str); A[0] = ‘1‘; printf("%u\n",A); printf("%u\n",str); return; } }; int main() { Same re; string str = "This is nowcoder"; printf("%u\n", &str); re.reverse(str.data()); cout<< str << " " << endl; return 0; }
为什么str的值被修改了呢?
string,const char*, char*转换之后还是指向同一片内存地址么?
标签:out eve ons void his const reverse main this
原文地址:https://www.cnblogs.com/yiyi20120822/p/11373291.html