Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
StudyCpp
Commits
aacaddcf
Commit
aacaddcf
authored
Nov 25, 2022
by
Administrator
Browse files
add namespace
parent
fff4c471
Changes
1
Hide whitespace changes
Inline
Side-by-side
03.Advanced/NameSpace.cpp
0 → 100644
View file @
aacaddcf
#include <iostream>
using
namespace
std
;
// 第一个命名空间
namespace
first_space
{
void
func
(){
cout
<<
"Inside first_space"
<<
endl
;
}
}
// 第二个命名空间
namespace
second_space
{
void
func
(){
cout
<<
"Inside second_space"
<<
endl
;
}
}
// 嵌套命名空间
namespace
third_space
{
void
func
()
{
cout
<<
"Inside third_space"
<<
endl
;
}
// 代码声明
namespace
fourth_space
{
void
func
()
{
cout
<<
"Inside fourth_space"
<<
endl
;
}
}
}
int
main
()
{
// 调用第一个命名空间中的函数
first_space
::
func
();
// 调用第二个命名空间中的函数
second_space
::
func
();
// 调用第三个命名空间中的函数
third_space
::
func
();
// 调用第四个命名空间中的函数
third_space
::
fourth_space
::
func
();
// 制定使用特定的命名空间后,可以隐式调用方法
using
namespace
third_space
::
fourth_space
;
// 隐式调用fourth_space中的func方法
func
();
return
0
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment