1.重载函数

2.内联函数

3.New、Delete

4.重载与、const形参

5.常数据成员

6.静态成员函数

==重载函数==
#include <iostream>
using namespace std;
void add(int x,int y)
{
cout<<x + y<<endl;
}
void add(float x)
{
cout<<x + 10<<endl;
}
double add(double x,double y)
{
return x + y;
}
int main()
{
add(1,6);
add(3.89);
cout<<add(1.2,1.6)<<endl;//函数名相同自动按传入的参数区分运行相应函数 return 0;
}
==内联函数==
#include <iostream>
//#include <string>
using namespace std;
inline void love(int i)
{
cout<<"我喜欢你"<<i<<"天了"<<endl;
}
int main()
{
for(int k=0;k<100000;k++)
love(k); //相当于函数在此镶嵌写入,比调用运行更快 return 0;
}
==New、Delete==
#include <iostream>
#include <string>
using namespace std;
int main()
{
int *pi= new int(10);
cout<<"*pi:"<<*pi<<endl;
*pi=20;
cout<<"*pi:"<<*pi<<endl;
char *pc= new char[10];
for(int i=0;i<10;i++)
pc[i]=i+65;
for(int k=0;k<10;k++)
cout<<pc[k]<<endl;
delete pi;
delete []pc;
return 0;
}
==重载与、const形参==
#include <iostream>
using namespace std;
void func1(const int *x)
{
cout<<"常量指针:"<<*x<<endl;
}
void func1(int *x)
{
cout<<"普通指针:"<<*x<<endl; }
void func2(const int&x)
{
cout<<"常量引用:"<<x<<endl;
}
void func2(int&x)
{
cout<<"普通引用:"<<x<<endl;
}
int main()
{
const int c=1;
int d=2;
func1(&c);//常量参数
func1(&d);//非~ func2(c);//常量参数
func2(d);//非~
return 0;
}
==常数据成员==
#include <iostream>
using namespace std;
class circle
{
public:
circle(double r);
double c_c();
private:
double R;
const double pai;
};
circle::circle(double r):pai(3.1415926)
{
R = r;
}
double circle::c_c()
{
return 2*pai*R ;
}
int main()
{
cout<<"请输入半径:"<<endl;
double pk;
cin>>pk;
circle q_c(pk);
cout<<"计算得周长为:"<<q_c.c_c()<<endl;
//system("pause");
return 0;
}
==静态成员函数==

#include <iostream>
#include <string>
using namespace std;
class student
{
public:
student (string name,int id);
string get_name();
static int get_total();
static int get_total(student&stdref);
private:
static int Total;
string Name;
int Id; };
student::student(string name,int id):Name(name)
{
Total++;
Id = id;
}
string student::get_name()
{
return Name;
}
int student::get_total(student&stdref)
{
cout<<stdref.Name<<"被清华录取了"<<endl;
return Total;
}
int student::get_total()
{
return Total;
}
int student::Total = 0;
int main()
{
cout<<"原来总人数"<<student::get_total()<<endl;
student std_tom("tom",12580);
cout<<"姓名:"<<std_tom.get_name()<<"\n变化后的总人数:"<<std_tom.get_total(std_tom)<<endl;
//通过访问对象访问静态成员函数
return 0; }

最新文章

  1. 【转】 linux之sed用法
  2. Linux系统编程-setitimer函数
  3. ELK-Python(一)
  4. Android IOS WebRTC 音视频开发总结(二七)-- whatsapp之转发优先
  5. GRUB加密
  6. netbeans设置字体
  7. C#中关于DateTime的最大值和最小值
  8. C语言库函数探究
  9. HTTP库Axios
  10. Jsの练习-数组常用方法 -splice()
  11. Hive 任务优化 tips
  12. 使用debootstrap制作debian-jessie系统docker镜像
  13. CNN做序列标注问题(tensorflow)
  14. Codeforces 785 D. Anton and School - 2
  15. mysql str_to_date 字符串 转日期时间
  16. Android Activity启动流程源码全解析(2)
  17. JQUERY dialog的用法详细解析
  18. 如何解决Maven速度慢
  19. 20145314郑凯杰《信息安全系统设计基础》第7周学习总结 part B
  20. makefile  模板 (template)

热门文章

  1. Dynamics CRM使用JS隐藏自定义按钮
  2. OOUnit4Summary
  3. OO UNIT 1 个人单元总结
  4. 配置动态刷新RefreshScope注解使用局限性(一)
  5. 大学四年,总结一套适合小白的Java自学路线和方法
  6. manjaro 手动调节屏幕亮度
  7. Civil3d中 如何用管轴线的变坡点桩号控制其他纵断面数据的显示?
  8. 《图解HTTP》部分章节学习笔记整理
  9. 1026 Table Tennis
  10. 服务器安装node全教程