Day 68 編寫string 類,友元函式

2021-09-27 11:18:11 字數 1630 閱讀 4516

1.懶漢模式多執行緒時是不安全的。

2.友元函式:

3.volatile 是禁止系統優化的意思。如果不禁止優化,系統可能取變數時不從記憶體中取,而是去暫存器中直接讀出。

4.簡單的說陣列就是一種資料型別,它的本質是具有:單一性,有序性,連續性;

5.stl是類模板庫,標準類模板庫。 vector < > v;

迭代器 【)左閉右開;

6.兩個指標不能相加, 但兩個指標可以相減,相減時必須基型別相同。值為相差基型別的個數;

short a = ;

short *p = &a[0];

short *q = &a[3];

cout << p - q << endl;

//結果為三;負三;

short a = ;

char *p = (char *)&a[0];

char *q = (char*)&a[3];

cout << q - p << endl;

cout << p - q << endl;

//結果為六;負六

short a = ;

int *p = (int *)&a[0];

int *q = (int*)&a[3];

cout << q - p << endl;

cout << p - q << endl;

//結果為1 ;-2;

#include

using namespace std;

class point

private:

int x, y;

//在這裡宣告函式distance為類point 的友元函式。

friend double distance(const point &p1,const point &p2);

//宣告類為友元類

friend class line;

//友元函式

double distance(const point &p1,const point &p2)

//友元類

class line

private:

point p1, p2;

int m_i;

friend class point;

};int main()

mystring(const mystring &other):mpstr(new char[strlen(other.mpstr)+1])

void show()

~mystring()

void assign(const char *p)

private:

char *mpstr;

int main()

{

mystring s1("hello");

s1.show();

mystring s2("world");

mystring s2(s1);

s2.show();

s1.show();

s1.assign(s1);

s1.show();

day11String類的常用方法

package a public class test1 static void f2 基本型別轉字串 static void f3 字串轉基本型別 static void f4 建立乙個字串 string s2 new string c system.out.println s1 system.o...

編寫類String的建構函式 析構函式和賦值函式

編寫類string的建構函式 析構函式和賦值函式,已知類string的原型為 class string public string const char str null 普通建構函式 string const string other 拷貝建構函式 string void 析構函式 string ...

編寫類String的建構函式 析構函式和賦值函式

已知類string的原型為 classstring 請編寫string的上述4個函式 普通建構函式 string string const char str else string的析構函式 string string void 拷貝建構函式 string string conststring ot...