C++記錄

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   資料   2014   ar   

1, a++與++a

 

2,

int a[10] ;

int* p = (int*)(&a + 1 ) ;

&a 是數組指標, 其類型為int (*)[10] ,   &a+1 表示 a + 10 .

a才是&a[0] .

(int*)(&a+1) - (int*)(&a) == 10 

 

3,

在預設建構函式內部再調用帶參的建構函式屬使用者行為而非編譯器行為,亦即僅執行函數調用,而不會執行其後的初始設定式。

只有在產生對象時,初始設定式才會隨相應的建構函式一起調用。

struct CLS{    int m_i;    CLS(int i): m_i( i ) { }    CLS()    {        CLS( 0 );//不會執行其後的初始設定式    }};int main(void){    CLS obj;    cout << obj.m_i << endl;    return 0;}    

 

4,

C++中的空類,預設產生哪些類成員函數

class Empty{    public:    Empty(); //預設建構函式    Empty(const Empty &); //拷貝建構函式    ~Empty(); //解構函式    Empty & operator=(const Empty &); //賦值運算子    Empty* operator&(); //取址運算子    const Empty* operator&() const; //取址運算子const};

 

 

5,

// 功能:由src所指記憶體地區複製count個位元組到dest所指記憶體地區。// 說明:src和dest所指記憶體地區可以重疊,但複製後dest內容會被更改。函數返回指向dest的指標void *memmove(void *dest , const void *src , size_t count){    assert( (dest != NULL) && (src != NULL));     //安全檢查    assert( count > 0 );    char *psrc = (char *) src;    char *pdest = (char *) dest;    //檢查是否有重疊問題    if( pdest < psrc )    {        //正向拷貝        while( count-- )            *pdest++ = *psrc++;    }    else if( psrc < pdest )    {        //反向拷貝        psrc = psrc + count - 1;        pdest = pdest + count - 1;        while( count-- )            *pdest-- = *psrc--;    }    return dest;}// 功能:由src指向地址為起始地址的連續n個位元組的資料複製到以dest指向地址為起始地址的空間內。// 說明:src和dest所指記憶體地區不能重疊,函數返回指向dest的指標void *memmcpy(void *dest , const void *src , size_t count){    assert( (dest != NULL) && (src != NULL));     //安全檢查    assert( count > 0 );    char *psrc = (char *) src;    char *pdest = (char *) dest;    while( count-- )        *pdest++ = *psrc++;    return dest;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.