From 8cf04481b7528369587b57d96142966321b8d72a Mon Sep 17 00:00:00 2001 From: huihut Date: Fri, 28 Feb 2020 22:01:37 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90@DiDongDongDi=20=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E6=94=B9=E8=8C=83=E5=9B=B4=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=AC=A6=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/huihut/interview/issues/12#issuecomment-592503223 --- README.md | 20 +++++++++++++------- docs/README.md | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e2b28f3..2dda88c 100644 --- a/README.md +++ b/README.md @@ -582,22 +582,28 @@ cout << x << endl; :: 使用 ```cpp -int count = 0; // 全局(::)的 count +int count = 11; // 全局(::)的 count class A { public: - static int count; // 类 A 的 count(A::count) + static int count; // 类 A 的 count(A::count) }; +int A::count = 21; + +void fun() +{ + int count = 31; // 初始化局部的 count 为 31 + count = 32; // 设置局部的 count 的值为 32 +} int main() { - ::count = 1; // 设置全局的 count 的值为 1 + ::count = 12; // 测试 1:设置全局的 count 的值为 12 - A::count = 2; // 设置类 A 的 count 为 2 + A::count = 22; // 测试 2:设置类 A 的 count 为 22 - int count = 0; // 局部的 count - count = 3; // 设置局部的 count 的值为 3 + fun(); // 测试 3 - return 0; + return 0; } ``` diff --git a/docs/README.md b/docs/README.md index a78a906..7910aba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -544,22 +544,28 @@ cout << x << endl; :: 使用 ```cpp -int count = 0; // 全局(::)的 count +int count = 11; // 全局(::)的 count class A { public: - static int count; // 类 A 的 count(A::count) + static int count; // 类 A 的 count(A::count) }; +int A::count = 21; + +void fun() +{ + int count = 31; // 初始化局部的 count 为 31 + count = 32; // 设置局部的 count 的值为 32 +} int main() { - ::count = 1; // 设置全局的 count 的值为 1 + ::count = 12; // 测试 1:设置全局的 count 的值为 12 - A::count = 2; // 设置类 A 的 count 为 2 + A::count = 22; // 测试 2:设置类 A 的 count 为 22 - int count = 0; // 局部的 count - count = 3; // 设置局部的 count 的值为 3 + fun(); // 测试 3 - return 0; + return 0; } ``` -- GitLab