零起点学通C++,P437,18—7—4 用复制构造函数实现字符串的初始化功能这段程序,为什么在调用String(const char*const ch); //带一个参数的构造函数用来初始化字符串
这个构造函数时,不会循环调用char&operator[](unsigned short int length); //按引用返回的下标运算符函数(该段程序在执行String s2("study");这一语句时,只输出:“构造函数....”,没有输出“operator[]执行”)
而调用复制构造函数时,就会循环调用char operator[](unsigned short int length)const; //按值返回的const下标运算符函数(该段程序在执行String s4=s3;时,循环执行重载[],结果输出“operator[]const执行 operator[]const执行 operator[]const执行...”
这是为什
这个构造函数时,不会循环调用char&operator[](unsigned short int length); //按引用返回的下标运算符函数(该段程序在执行String s2("study");这一语句时,只输出:“构造函数....”,没有输出“operator[]执行”)
而调用复制构造函数时,就会循环调用char operator[](unsigned short int length)const; //按值返回的const下标运算符函数(该段程序在执行String s4=s3;时,循环执行重载[],结果输出“operator[]const执行 operator[]const执行 operator[]const执行...”
这是为什