mw 发帖数: 525 | 1 我当我把substr的返回值改成实际的变量而不是reference,程序就编译不了了。。。。
请问谁知道是怎么回事吗?
为什么at()里面的throw没法工作呢?
#include
#include
using namespace std;
class mstring{
public:
const char* c_str() const{
return _arr;
}
unsigned int c_len() const{
return _len;
}
void print(){
printf("%s\n", _arr);
}
public:
mstring(){
_len = 0;
_arr = 0;
}
mstring(unsigned int ilen){
_len = ilen;
_ |
t****t 发帖数: 6806 | 2 change your copy constructor signature to
mstring(const mstring&)
。。
【在 mw 的大作中提到】 : 我当我把substr的返回值改成实际的变量而不是reference,程序就编译不了了。。。。 : 请问谁知道是怎么回事吗? : 为什么at()里面的throw没法工作呢? : #include : #include : using namespace std; : class mstring{ : public: : const char* c_str() const{ : return _arr;
|
mw 发帖数: 525 | 3 yah, that's it, thanks a lot!
can you also help to give a clue --- "why?"
【在 t****t 的大作中提到】 : change your copy constructor signature to : mstring(const mstring&) : : 。。
|
h***z 发帖数: 233 | 4 The semantics of copying that we expect is that the original is not modified
by the copy action. Requiring copy constructor argument to be a const
reference would make this behavior consistent with what we expect. |
k**f 发帖数: 372 | 5 A side topic from LZ's post, where the data members are named with leading
underscores. I've read elsewhere that this is not a good practice.
What do you guys think? |