当前位置:网站首页>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
边栏推荐
- 高薪程序员&面试题精讲系列120之Redis集群原理你熟悉吗?如何保证Redis的高可用(上)?
- Data security -- 12 -- Analysis of privacy protection
- What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
- EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
- What is CGI, IIS, and VPS "suggested collection"
- Kivy tutorial of setting the size and background of the form (tutorial includes source code)
- Win11远程桌面连接怎么打开?Win11远程桌面连接的五种方法
- MySQL split method usage
- ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
- 抖音或将推出独立种草社区平台:会不会成为第二个小红书
猜你喜欢
各路行业大佬称赞的跨架构开发“神器”,你get同款了吗?
案例大赏:英特尔携众多合作伙伴推动多领域AI产业创新发展
[written to the person who first published the paper] common problems in writing comprehensive scientific and Technological Papers
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
In cooperation with the research team of the clinical trial center of the University of Hong Kong and Hong Kong Gangyi hospital, Kexing launched the clinical trial of Omicron specific inactivated vacc
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
Introduction to the PureMVC series
图灵诞辰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
acwing 843. n-皇后问题
随机推荐
Camera calibration (I): robot hand eye calibration
Poor math students who once dropped out of school won the fields award this year
EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
广告归因:买量如何做价值衡量?
Surpassing postman, the new generation of domestic debugging tool apifox is elegant enough to use
EasyCVR集群重启导致其他服务器设备通道状态离线情况的优化
Practice Guide for interface automation testing (middle): what are the interface testing scenarios
[knife-4j quickly build swagger]
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
抖音或将推出独立种草社区平台:会不会成为第二个小红书
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
[untitled]
【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
Oracle -- 视图与序列
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
过气光刻机也不能卖给中国!美国无理施压荷兰ASML,国产芯片再遭打压
leetcode 53. Maximum subarray maximum subarray sum (medium)