diff options
author | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-28 05:18:53 +0000 |
---|---|---|
committer | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-28 05:18:53 +0000 |
commit | d3eecdd6edebe3fd2e847099abe02476bdcf7f57 (patch) | |
tree | 76a348e5add320b599ccf019aac719c4f2267246 /base/callback.h | |
parent | 63e468645ea8c3f6fd8d5bc0af3b77b11736b5e7 (diff) | |
download | chromium_src-d3eecdd6edebe3fd2e847099abe02476bdcf7f57.zip chromium_src-d3eecdd6edebe3fd2e847099abe02476bdcf7f57.tar.gz chromium_src-d3eecdd6edebe3fd2e847099abe02476bdcf7f57.tar.bz2 |
Clarify callback.h const reference binding documentation.
NOTRY=true
Review URL: https://codereview.chromium.org/81713003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback.h')
-rw-r--r-- | base/callback.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/base/callback.h b/base/callback.h index ade3f8c..a962957 100644 --- a/base/callback.h +++ b/base/callback.h @@ -214,11 +214,16 @@ // // PASSING PARAMETERS BY REFERENCE // -// void foo(int arg) { cout << arg << endl } +// Const references are *copied* unless ConstRef is used. Example: +// +// void foo(const int& arg) { printf("%d %p\n", arg, &arg); } // int n = 1; +// base::Closure has_copy = base::Bind(&foo, n); // base::Closure has_ref = base::Bind(&foo, base::ConstRef(n)); // n = 2; -// has_ref.Run(); // Prints "2" +// foo(n); // Prints "2 0xaaaaaaaaaaaa" +// has_copy.Run(); // Prints "1 0xbbbbbbbbbbbb" +// has_ref.Run(); // Prints "2 0xaaaaaaaaaaaa" // // Normally parameters are copied in the closure. DANGER: ConstRef stores a // const reference instead, referencing the original parameter. This means |