Road C ++ learning --1

One double Risk number Transport Count symbol n a m e s p a c e \ Color {red} {a double colon operator namespace}

Direct plus global scope:

two Life name air between n a m e s p a c e \ Color {red} {Second, namespace namespace}

namespace namespace mainly used to solve the problem of naming conflicts


namespce A
{
	int m_b = 100;
}

1, can be put in the namespace functions, variables, structure, class
2, then the namespace must be defined global variables

namespace A
{
	void func()
	int m_a=20;
	struct person
	{
	};
	class Animal{};
	namespace B
	{
		int m_a = 10;
	}	
}

3, can be nested namespaces

namespace A
{
	namespace B
	{
		int m_a = 10;
	}	
}

4, the namespace is open, you can go at any time of the original namespace additions to this A namespace will be merged and above namespace A

namespace A
{
	int m_a=0; //相当于static int m_c,只能在当前文件夹使用
}
namespace A
{
	int m_a = 10;
}	

5, nameless, anonymous namespace

namespace 
{
	int m_c=0; //相当于static int m_c,只能在当前文件夹使用
}

6, can play a namespace alias

namespace veryLongName
{
	int m_c=0; //相当于static int m_c,只能在当前文件夹使用
}
void test()
{
	namespace short = veryLongName;
}

three in s i n g \color{red}{ 三、 using}

First look at a problem
Here Insert Picture Description
output is 20, and add a statement after the error has occurred!
Here Insert Picture Description
Compiler directives
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_43615373/article/details/90272469