https://iattempt.net

Ernest 發表在 痞客邦 留言(0) 人氣()

<article class="mx-1 my-1">
<h3>目錄</h3>
<ul>
    <li><a href="#%E7%9B%AE%E7%9A%84">目的</a></li>
    <li><a href="#%E5%95%8F%E9%A1%8C%E8%88%87%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88">問題與解決方案</a>
<ul>
    <li><a href="#namespace-%E5%90%8D%E7%A8%B1%E6%B1%A1%E6%9F%93%E8%88%87%E8%A1%9D%E7%AA%81">namespace-解決名稱污染與衝突</a></li>
    <li><a href="#using-declaration/using-directive-%E6%B8%9B%E5%B0%91%E4%B8%8D%E6%96%B7%E5%87%BA%E7%8F%BE%E7%9A%84%E8%B3%87%E6%A0%BC%E4%BF%AE%E9%A3%BE%E8%A9%9E">using declaration / using directive-減少不斷出現的資格修飾詞</a></li>
    <li><a href="#using-declaration/using-directive-%E5%B8%B6%E4%BE%86%E7%9A%84%E5%8D%B1%E9%9A%AA%E6%80%A7">using declaration / using directive-帶來的危險性</a></li>
    <li><a href="#using-declaration/using-directive-%E5%B7%AE%E5%88%A5%E4%B8%8D%E5%83%85%E5%83%85%E5%9C%A8%E6%96%BC%E5%AE%A3%E5%91%8A%E7%AF%84%E5%9C%8D">using declaration / using directive-差別不僅僅在於宣告範圍</a></li>
</ul>
</li>
</ul>
<h3 id="目的">目的</h3>
使用Namespace可以提供、解決以下問題:
<ul>
    <li>名稱污染、衝突</li>
    <li>程式碼模組化</li>
    <li>有邏輯的組織程式碼</li>
</ul>
此外以下為本文使用的名稱(參考[1])所對應之意義
<ul>
    <li>資格修飾詞:std::、::(全域)</li>
    <li>using declaration:using std::string;</li>
    <li>using direction:using namespace std;</li>
</ul>

Ernest 發表在 痞客邦 留言(0) 人氣()

<article class="mx-1 my-1">
<h4>正文</h4>
稍微了解過template以後,我們就可以看懂以下的程式碼(這邊用class而非typename,是想表明_Derived只會是一個使用者自訂型別):
<!--more-->
<pre>----main.cpp
    #include 
    using namespace std;

Ernest 發表在 痞客邦 留言(0) 人氣()


目錄
  • with POD

  • with pointer / reference

  • with function / member function

  • with alias (typedef / using)

  • 目的
    由簡入繁介紹使用方法

    本文
    With Plain Old Data
    int const ic; // const variable
    const int ci; // == ic
    With pointer/reference
    int const * ic_p; // const variable, normal pointer
    const int * ci_p; // == ic_p
    int *const i_pc; // normal variable, const pointer
    int const *const ic_pc; // const variable, const pointer
    const int *const ci_pc; // == ic_pc
    int &const i_rc; // Error,&const is not a declartor operator [1]
    // reference is already h== const mean.
    int const & ic_r; // const variable, reference
    const int & ci_r; // == ic_r
    With function/member function
    class test{
    public:
    void foo() const{
    // if instance of Class:test is defined const, then call this function
    pri_i=10; // Error, this function cannot change inner variable
    pub_i=10; // Error, == pri_i, visibility of instance's variable is not influent for const
    sta_i=10; // Pass, static variable belongs Class
    }
    void foo() {
    // if instance of Class:test
    // is non-const or not exactly append const
    // of same funciton
    // then this function will called
    // do something...
    }
    int pub_i;
    private:
    int pri_i;
    static int sta_i;
    };
    With alias (typedef/using)
    typedef int * t_ip;
    t_ip const t_ipc; // normal variable and const pointer
    const tip ct_ip; // == t_ipc
    using u_ip = int *;
    u_ip const u_ipc; // == t_ipc
    const u_ip cu_ip; // == t_ipc
    // 如果你想要定義一個const variable,那必須於宣告別名時定義之:
    typedef int const * t_icp; // const int and normal pointer
    typedef const int * t_cip; // == t_icp
    t_icp const t_icpc; // const int and const pointer
    const ticp ct_icp; // == t_icpc
    // using and typedef are the same
    參考資料
  • TCPL *, &和*const皆是declarator operator

  • Ernest 發表在 痞客邦 留言(0) 人氣()

    <article class="mx-1 my-1">
    <h3>目錄</h3>
    <ul>
        <li><a href="#pointer/reference的宣告/定義式">pointer / reference的宣告/定義式</a></li>
        <li><a href="#一個int被pointer所指">int *p:一個int被pointer所指</a></li>
        <li><a href="#一個pointer被pointer所指">int **pp:一個pointer被pointer所指</a></li>
        <li><a href="#一個int被reference所參照">int &r:一個int被reference所參照</a></li>
        <li><a href="#一個pointer被reference所參照">int *&pr:一個pointer被reference所參照</a></li>
        <li><a href="#%E7%B8%BD%E7%B5%90">總結</a></li>
    </ul>
    <h3>正文</h3>

    Ernest 發表在 痞客邦 留言(0) 人氣()

    <article class="mx-1 my-1">
    <h3>目錄</h3>
    <ol>
        <li><a href="#%E7%89%A9%E4%BB%B6%E7%9A%84%E7%89%B9%E6%80%A7">物件的特性</a></li>
        <li><a href="#lvalue%E8%88%87prvalue">lvalue與prvalue</a></li>
        <li><a href="#lvalue%E8%88%87prvalue%E5%9C%A8%E5%AF%A6%E9%9A%9B%E7%A8%8B%E5%BC%8F%E7%9A%84%E9%81%8B%E4%BD%9C">lvalue與prvalue在實際程式的運作</a></li>
        <li><a href="#xvalue%E8%88%87move-semantic">xvalue與move semantic</a></li>
        <li><a href="#%E7%B8%BD%E7%B5%90">總結</a></li>
    </ol>

    Ernest 發表在 痞客邦 留言(2) 人氣()

    chmod rwx name : change the file/directory to given mode
     

    Ernest 發表在 痞客邦 留言(0) 人氣()

    set tags+=~/.vim/tags/cpp_src/tags " 设置tags搜索路径
    set wildmode=longest,list " Ex命令自动补全采用bash方式"
    set nocp
    set nu
    syntax on
    set tabstop=4
    set autoindent
    set shiftwidth=4
    set expandtab

    Ernest 發表在 痞客邦 留言(0) 人氣()

    cin.tie(0)
    解除 cin 與 cout 的綁定,亦即ostream不會在istream要輸入時被flush

    Ernest 發表在 痞客邦 留言(0) 人氣()

    不見得!
    編譯器自己也能進行優化的動作,

    Ernest 發表在 痞客邦 留言(0) 人氣()


    以下請注意大小寫
     

    Ernest 發表在 痞客邦 留言(0) 人氣()

    bit  address:  可以視為一個一維大陣列,每個bit能存1/0(高低電位)
    byte address:  每一個元素為一個位元組的大小,也就是8個bit

    Ernest 發表在 痞客邦 留言(0) 人氣()

    1 2
    Blog Stats
    ⚠️

    成人內容提醒

    本部落格內容僅限年滿十八歲者瀏覽。
    若您未滿十八歲,請立即離開。

    已滿十八歲者,亦請勿將內容提供給未成年人士。