1.
普通方法中可以调用常方法
但是常方法中不能调用普通方法
2. String 完整版
#include#include #include #include using namespace std; class String { protected: struct StrNode { int ref; //引用指向 int len; //字符串长度 int size; //柔性数组的长度 char data[]; }; private: StrNode *pstr; String(StrNode *p) :pstr(p) {} public: String(const char *p = NULL) :pstr(NULL) { if (p != NULL) { int sz = strlen(p); pstr = (StrNode*)malloc(sizeof(StrNode)+sz * 2 + 1); pstr->ref = 1; pstr->len = sz; strcpy(pstr->data, p); pstr->size = sz * 2; } } ~String() { if (pstr != NULL&&--pstr->ref == 0) { free(pstr); } pstr = NULL;



