Skip to content

Commit c1635d0

Browse files
authored
Update README.md
1 parent 2e087d1 commit c1635d0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

basic_content/static/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Welcome to Apple!
248248

249249
**限定访问范围**
250250
static还有限定访问范围的作用(类似于匿名名字空间)。来自issue:https://github.com/Light-City/CPlusPlusThings/issues/142
251-
251+
```cpp
252252
// source1.cpp
253253
extern void sayHello();
254254
const char* msg = "Hello World!\n";
@@ -265,8 +265,9 @@ void sayHello()
265265
{
266266
printf("%s", msg);
267267
}
268+
```
268269
g++对于上面两个代码文件是可以正常编译并且打印Hello World!,但如果给source1.cpp中的msg加上static,则会导致undefined reference to 'msg'的编译错误:
269-
270+
```cpp
270271
// source1.cpp
271272
extern void sayHello();
272273
static const char* msg = "Hello World!\n";
@@ -275,3 +276,4 @@ int main()
275276
sayHello();
276277
return 0;
277278
}
279+
```

0 commit comments

Comments
 (0)