当前位置:网站首页>Introduction to namespace Basics
Introduction to namespace Basics
2022-07-07 04:38:00 【Just stay at home】
In cooperative programming with others , Naming conflicts may occur . And the bigger the project , The more trouble the naming conflict causes .
So is there any way that we can use the same name without using conflict , Here is to introduce C++ In grammar namespace Namespace .
Catalog
One . Basic usage
namespace Namespaces can store variables , Structure , Function, etc. . When using, we need to define namespace To declare .
For example, we want to define two functions car, It also needs to be called in the same main function , Then you can define two namespace To store these two functions separately . Directly call... In the main function namespace that will do
call namespace We need to use the scope symbol (::). For example, in the following program , When we want to use BYD Of car when , Just call in the main function BYD::car() that will do . This is equivalent to telling the computer , When it sees :: The symbol , It needs to be in BYD This namespace Find car function . Don't look for other places , Not if you find it .
Functions can be defined directly in the namespace namespace Directly in , Of course , It can also be defined outside the domain like the following program . At this time , When defining functions , Call the namespace first , Let the computer know that I want to define something namespace The function in .
Two . Standard library
Using the standard library std When , We have three calling methods .
One , Is used every time a standard library function is called std::.
Two , Is to define the standard library for global use , That is to say in the header using namespace std; .
The first method is too cumbersome , The second definition is global and may cause conflict , Then we can use the third definition method .
3、 ... and , Define high-frequency objects as global use . namely using std:: object .
It's not easy to create , Let's support San Lian If there is a mistake , Please correct
边栏推荐
- Lessons and thoughts of the first SQL injection
- AI 落地新题型 RPA + AI =?
- Digital chemical plant management system based on Virtual Simulation Technology
- Dab-detr: dynamic anchor boxes are better queries for Detr translation
- What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- The request request is encapsulated in uni app, which is easy to understand
- 高薪程序员&面试题精讲系列120之Redis集群原理你熟悉吗?如何保证Redis的高可用(上)?
- See Gardenia minor
- Both primary and secondary equipment numbers are 0
猜你喜欢
The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
See Gardenia minor
树与图的深度优先遍历模版原理
kivy教程之设置窗体大小和背景(教程含源码)
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
Win11 control panel shortcut key win11 multiple methods to open the control panel
On the 110th anniversary of Turing's birth, has the prediction of intelligent machine come true?
Lessons and thoughts of the first SQL injection
图灵诞辰110周年,智能机器预言成真了吗?
随机推荐
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
[knife-4j quickly build swagger]
NanopiNEO使用开发过程记录
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
一图看懂!为什么学校教了你Coding但还是不会的原因...
英特尔David Tuhy:英特尔傲腾技术成功的原因
主设备号和次设备号均为0
测试/开发程序员怎么升职?从无到有,从薄变厚.......
【自动化经验谈】自动化测试成长之路
[untitled]
Master the secrets of software security testing methods, and pinch the security test report with your hands
sscanf,sscanf_ S and its related usage "suggested collection"
EasyCVR平台接入RTMP协议,接口调用提示获取录像错误该如何解决?
Lessons and thoughts of the first SQL injection
两个div在同一行,两个div不换行「建议收藏」
Win11控制面板快捷键 Win11打开控制面板的多种方法
一度辍学的数学差生,获得今年菲尔兹奖
Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
广告归因:买量如何做价值衡量?
Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist