<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 結構體(struct) `Solidity`提供`struct`來定義自定義類型。我們來看看下面的例子: ``` pragma solidity ^0.4.0; contract CrowdFunding{ struct Funder{ address addr; uint amount; } struct Campaign{ address beneficiary; uint goal; uint amount; uint funderNum; mapping(uint => Funder) funders; } uint compaingnID; mapping (uint => Campaign) campaigns; function candidate(address beneficiary, uint goal) returns (uint compaingnID){ // initialize campaigns[compaingnID++] = Campaign(beneficiary, goal, 0, 0); } function vote(uint compaingnID) payable { Campaign c = campaigns[compaingnID]; //another way to initialize c.funders[c.funderNum++] = Funder({addr: msg.sender, amount: msg.value}); c.amount += msg.value; } function check(uint comapingnId) returns (bool){ Campaign c = campaigns[comapingnId]; if(c.amount < c.goal){ return false; } uint amount = c.amount; // incase send much more c.amount = 0; if(!c.beneficiary.send(amount)){ throw; } return true; } } ``` 上面的代碼向我們展示的一個簡化版的眾籌項目,其實包含了一些`struct`的使用。`struct`可以用于映射和數組中作為元素。其本身也可以包含映射和數組等類型。 我們不能聲明一個`struct`同時將這個`struct`作為這個struct的一個成員。這個限制是基于結構體的大小必須是有限的。 雖然數據結構能作為一個`mapping`的值,但數據類型不能包含它自身類型的成員,因為數據結構的大小必須是有限的。 需要注意的是在函數中,將一個`struct`賦值給一個局部變量(默認是storage類型),實際是拷貝的引用,所以修改局部變量值時,會影響到原變量。 當然,你也可以直接通過訪問成員修改值,而不用一定賦值給一個局部變量,如`campaigns[comapingnId].amount = 0`
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看