From 9d86e03845b5a87de26fd2868097af0884370622 Mon Sep 17 00:00:00 2001 From: clarelsy Date: Sat, 16 Apr 2016 23:17:44 -0400 Subject: [PATCH 1/2] Update README.md We may use subscript only on a non-const map. --- ch11/README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ch11/README.md b/ch11/README.md index 39665a26..159b9035 100644 --- a/ch11/README.md +++ b/ch11/README.md @@ -113,14 +113,7 @@ const string& transform(const string &s, const map &m) return m[s]; } ``` -Such code could be explained as following pseudocode: -```python - if m contains key s: - return m[s] - else: - insert pair {s, ""} into m - return m[s] // That is an empty string -``` +The above code won't compile because the subscript operator might insert an element (when the element with the key s is not found), and we may use subscript only on a map that is not const. ## Exercise 11.35: >In buildMap, what effect, if any, would there be from rewriting `trans_map[key] = value.substr(1);` as `trans_map.insert({ key, value.substr(1) })`? From b743440304db973d61128f9b9d123f5161bfe72c Mon Sep 17 00:00:00 2001 From: Renjun Zheng Date: Mon, 18 Apr 2016 21:03:00 -0400 Subject: [PATCH 2/2] fix the problem of initialize static class variable --- ch13/ex13_17_2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch13/ex13_17_2.cpp b/ch13/ex13_17_2.cpp index 7d243e08..0b28c51c 100644 --- a/ch13/ex13_17_2.cpp +++ b/ch13/ex13_17_2.cpp @@ -26,7 +26,7 @@ class numbered { static int unique; }; -static int unique = 10; +int numbered::unique = 10; void f(numbered s) { std::cout << s.mysn << std::endl;