#include <iostream> class A { private: std::string a; public: A(std::string b) :a(b){} char& operator[](int b)const { return a[b]; } }; int main() { A a("hello"); //a[0]=‘j‘; 不能 char*p = &a[0]; *p = ‘j‘; 也不能,编译器信息:“return”: 无法从“const char”转换为“char &” std::cout << *p; }
时间: 2024-10-07 13:16:34