用c編寫類string的建構函式拷貝建構函式析

2021-03-03 21:48:52 字數 1553 閱讀 5151

1樓:匿名使用者

你看看bai這du

個,裡zhi面dao

好像就回有答

能不能幫忙寫一下c++類的建構函式,拷貝建構函式,賦值運算子=號的操作符過載,解構函式?求教!

2樓:愛夜

class test

;test::test(void)

test::test(test& item) //拷貝this->data = new char[itemlen];

p = this->data;

q = item.data;

while( itemlen-- &&(*p++ = *q++));

return;

}void test::operator=(test& item)this->len = item.len;

if( this->len == 0 )

this->data = new char[itemlen];

p = this->data;

q = item.data;

while( itemlen-- &&(*p++ = *q++));

return;

}test::~test()

}test::test(char * item,int n)this->data = new char[n];

p = this->data;

q = item;

while( len-- &&(*p++ = *q++));

return;}

定義一個mystring類如下,該類有建構函式、拷貝建構函式、解構函式、成員函式和靜態成員函式,

3樓:匿名使用者

#include

using namespace std;

class mystring ;

mystring::mystring(const char *s)

mystring::mystring(int n, char ch)

mystring::~mystring()

const char *mystring::c_str()

int mystring::getnumberofobjects()

// 類靜態變數初始化

int mystring::numberofobjects = 0;

int main()

cout << ptr_ms2->c_str() << endl;

delete ptr_ms2;

cout << mystring::getnumberofobjects() << endl;

return 0;}

求用C 編寫幾何圓形的類Circle,包括兩個屬性 圓心O和半徑R

point類不用寫了吧,就兩個座標 class circle point geto int getr void setr int r void moveto point p void seto point p void display private point p int r point類要過載運...

如何將c中的指標指向string類的其中某字元

1 string類成員函式c str 的原型 const char c str const 返回一個以null終止的c字串 2 c str 函式返回一個指向正規c字串的指標,內容和string類的本身物件是一樣的,通過string類的c str 函式能夠把string物件轉換成c中的字串的樣式 3 ...

用C 編寫類,要原創的,我是大一的,學的是譚浩強的C 程式設計(第二版)。不需要太複雜,也

二維矩陣類 class matrix public matrix int mm,int nn public matrix int mm,int nn,floatarr 設定m,n public void set mn int mm,int nn 設定m public void set m int m...