We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2e087d1 commit c1635d0Copy full SHA for c1635d0
basic_content/static/README.md
@@ -248,7 +248,7 @@ Welcome to Apple!
248
249
**限定访问范围**
250
static还有限定访问范围的作用(类似于匿名名字空间)。来自issue:https://github.com/Light-City/CPlusPlusThings/issues/142
251
-
+```cpp
252
// source1.cpp
253
extern void sayHello();
254
const char* msg = "Hello World!\n";
@@ -265,8 +265,9 @@ void sayHello()
265
{
266
printf("%s", msg);
267
}
268
+```
269
g++对于上面两个代码文件是可以正常编译并且打印Hello World!,但如果给source1.cpp中的msg加上static,则会导致undefined reference to 'msg'的编译错误:
270
271
272
273
static const char* msg = "Hello World!\n";
@@ -275,3 +276,4 @@ int main()
275
276
sayHello();
277
return 0;
278
279
0 commit comments