Why Const Matters
Posted on May 31st, 2008 at 16:51 by fr3@K

假設我們需要按照順序以紙條對 Alice 與 Bob 打招呼:

    void Alice(string& message_to_alice);
    void Bob(const string& message_to_bob);
    

天知道 Alice 會對我的紙條做什麼? 為了安全起見, 還是多寫一份紙條:

    int main()
    {
      string my_message = "hello";
    
      string a_copy_of_my_message = my_message;
      Alice(a_copy_of_my_message);
    
      Bob(my_message);
    
      return 0;
    }
    

否則可能我問候的就不是 Bob, 而是 Bob 的老師了.

del.icio.us:Why Const Matters digg:Why Const Matters spurl:Why Const Matters newsvine:Why Const Matters furl:Why Const Matters Y!:Why Const Matters 黑米共享書籤:Why Const Matters 推推王:Why Const Matters
Previous Post
« CONST LPLONG «
Next Post
» Containers with Stateful Allocator, a Bug in C++98 »

Zero Comments »

No comments yet.

Comments RSS TrackBack URI

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>