C const修飾的是誰?

2021-09-12 05:34:01 字數 601 閱讀 4204

實驗**如下:

class test

void var(int a,int b) const //const修飾的this指標。,var(const test *this,int a,int b )

private:

int a;

int b;

};int main()

說明:上面的 this->a = 100; this->b = 188; 是錯誤的,因為const修飾的this指標,再次修改這個值的時候就出現了錯誤。

全域性函式轉換成員函式少了乙個引數。

**:

class test

public:

test(int a=0, int b=1)

public:

void printt()

private:

};//全域性函式的方法。實現t1+t2;

test testadd(test &a1, test &a2)

void printt(test *pt)

int main()

const 修飾的是誰

const 修飾乙個量,那個量會被放到乙個常量表裡,無論如何,值都不會被改變了 const 修飾指標 int a 3 int p a const int p 指標所指向的記憶體空間無法被改變,即a的值無法被改變 int const p 指標的值無法被改變,即指標只能指向某乙個特定的記憶體空間,這裡只...

C const修飾符的作用

修飾變數 const int a 10 變數a為整型常量,值為10,不可修改 修飾引用 const int b a b為變數a的常量引用,不可通過引用修改變數 修飾引數 a const 只能修飾輸入引數 b const 修飾 指標傳遞 的引數,在左邊則修飾指標指向的內容,以防意外改動指標所指資料 v...

C const修飾引用和指標

測試 void constbeforefunction const double x,const std array d condition,const std array s condition 以下報錯 x 1.0 d condition at 0 1 d condition at 1 2 d ...