C++ Day1

cpp 复制代码
#include<iostream>

void test1()
{
	using namespace std;//展开标准命名空间
	//全展开
	cout << "hello world!x" << endl;
}
void test2()
{
	std::cout << "hello world!xx" << std::endl;
	//部分展开,使用时展开
}
void test3()
{
	using std::cout;
	using std::endl;
	//部分展开,展开后使用
	cout << "hello world!xxx" << endl;
}
namespace A
{
	int a = 10;
	namespace B
	{
		int b = 5;
		namespace C
		{
			int c = 2;
			//命名空间的嵌套
		}
	}
}
//不缺省
int ADD1(int a, int b)
{
	return a + b;
}
//部分缺省
//int ADD2(int a = 0, int b) {}//从左往右缺省没有意义,第一个数始终要赋值才能到第二个参数缺省
int ADD3(int a, int b = 10)
{
	return a + b;
}
//全缺省
int ADD4(int a = 1, int b = 1)
{
	return a + b;
}
int A(int a,int b,int c){}//_Z1Aiii
int A(int a,int b){}//个数不同构成重载,_Z1Aii
int A(int a,float b,double c){}//类型不同构成重载,_Z1Aifd
int A(float a,int b,double c){}//类型的顺序不同构成重载,_Z1Afid
//错误示例:
int A(int b, int a, int c) {}//类型相同,顺序相同,变量的名字不同不构成重载,_Z1Aiii
int main()
{
	test1();
	test2();
	test3();
	//namespace B
	//{}
	//命名空间只能在全局范围中定义,局部范围不能定义
	std::cout << ADD1(2, 3) << std::endl;//不缺省
	std::cout << ADD3(10) << std::endl;//部分缺省
	std::cout << ADD4() << std::endl;//全缺省
	return 0;
}
相关推荐
future14121 小时前
C#学习日记
开发语言·学习·c#
码农编程录1 小时前
【c/c++3】类和对象,vector容器,类继承和多态,systemd,std&boost
c++
king_harry1 小时前
Java程序-OceanBase Connector/J 示例
开发语言
martian6652 小时前
支持向量机(SVM)深度解析:从数学根基到工程实践
算法·机器学习·支持向量机
孟大本事要学习2 小时前
算法19天|回溯算法:理论基础、组合、组合总和Ⅲ、电话号码的字母组合
算法
傻啦嘿哟2 小时前
Python 办公实战:用 python-docx 自动生成 Word 文档
开发语言·c#
翻滚吧键盘2 小时前
js代码09
开发语言·javascript·ecmascript
q567315232 小时前
R语言初学者爬虫简单模板
开发语言·爬虫·r语言·iphone
??tobenewyorker2 小时前
力扣打卡第二十一天 中后遍历+中前遍历 构造二叉树
数据结构·c++·算法·leetcode
贾全3 小时前
第十章:HIL-SERL 真实机器人训练实战
人工智能·深度学习·算法·机器学习·机器人