C++?????????????????
???????????? ???????[ 2013/4/27 9:55:45 ] ????????
??????????????????????????? ???????String????????
class String
{
public:
String(const char *str = NULL);// ?????????
String(const String &other); // ?????????
~ String(void); // ????????
String & operate =(const String &other);// ????????????
private:
char *m_data;
};
?????????????String???????????
??????????漰???????????????????????????????????????????????????????????????ο?c++ primer??13??
????1???????????
????????????????????????????βΣ????β??????????????????const???????????????????????????????г?????????????????????????????????????????????????????????????????????????????????????????
????a??????βα????????????????′???
class A
{
private:
int value;
public:
A(int n){value=n;}
A(A other){value=other.value;}
void functionA(){};
~A(){}
};
int main(void)
{
A a = 10;
A b = a;
b.functionA();
}
???????????δ???????????????????????????У????????A(A other)?????????????A b = a ????????A??A other??????a?????βθ??????Σ????????A(A other)???????????????????????е??ù????????γ?????????顣????C++??????????????????????????????????A(const A& other)??
????b????????????帴?????????
?????????????ж??帴?????????????????????????????????????????????????????????????????????????????????
??????????????????г?????????????????????????????????帴??????????????????漰????????????????????????????????????A??char *str ????????????飩??????????????????????????????η???B:str=new char[length+1]; if(str!=NULL);strcpy(str??A.str);?????????????????????????????η????????B??str=A.str?????????????
?????????????????????帴??????????????private????
??????????????String????????????????????£?
String::String(const String& other)
{
int length = strlen(other.m_data);
m_data = new char[length+1]; //???'