2016年6月15日

C++ 函数的扩展④--函数重载与函数指针

摘要: //函数扩展--函数重载与函数指针 #include using namespace std; //函数参数类型不同 void Fuc(char * b){ printf("%s\n",b); } //函数参数个数不同 int Fuc(int a, int b){ return a + b; } //函数参数类型不同 void Fuc2(const char * b){ ... 阅读全文

posted @ 2016-06-15 16:38 寒魔影 阅读(225) 评论(0) 推荐(0)

C++ 函数的扩展③--函数重载

摘要: //函数扩展--函数重载(C语言不支持函数重载) #include using namespace std; //函数重载在本质上是相互独立的不同函数(静态链编),在c++编译器编译就已经确定各个函数 //重载函数的函数类型是不同的 //函数返回值不能作为函数重载的依据 //函数重载是由参数列表决定的 //函数参数类型不同 void Fuc(char * b){ printf("%s... 阅读全文

posted @ 2016-06-15 16:22 寒魔影 阅读(225) 评论(0) 推荐(0)

C++ 函数的扩展②

摘要: //函数扩展--默认参数和占位参数 (了解) #include using namespace std; /* 可以将占位参数与默认参数结合起来使用 意义 为以后程序扩展留下线索 兼容C语言程序中可能出现的不规范写法 c++可以声明占位参数,占位参数一般用于程序扩展和对c代码的兼容 */ int Fuc(int a, int b, int=0){ return a + b; } vo... 阅读全文

posted @ 2016-06-15 16:07 寒魔影 阅读(228) 评论(0) 推荐(0)

C++ 函数的扩展①

摘要: //函数扩展--内联函数 inline #include using namespace std; /* c++中const常量可以替代宏常数定义 如: const int A = 3; 近似于 #define A 3 但是 const无法替代宏代码片段 c++中推荐使用内联函数替代宏代码片段 c++中使用inline关键字声明内联函数 内联函数声明时inline关键字必须和函数定义结合在... 阅读全文

posted @ 2016-06-15 15:42 寒魔影 阅读(881) 评论(0) 推荐(1)

C++ const关键字修饰引用

摘要: //const修饰引用的两种用法 #include using namespace std; struct Teacher{ char name[30]; int age; }; void SetA(const Teacher &t1){ //t1.age = 13; //报错 error C3490: 由于正在通过常量对象访问“age”,因此无法对其进行修... 阅读全文

posted @ 2016-06-15 12:11 寒魔影 阅读(342) 评论(0) 推荐(0)

C++ 指针引用

摘要: //指针引用 #include using namespace std; struct Teacher{ char name[30]; int age; }; int InitA(Teacher **pout/*out*/){ int ERRO_MSG = 0; if (pout==NULL) { ERRO_MSG = 1; ... 阅读全文

posted @ 2016-06-15 10:15 寒魔影 阅读(244) 评论(0) 推荐(0)

C++ 引用做左值

摘要: //引用做左值 #include<iostream> using namespace std; int SetA(int *p){ *p = 30; return *p; } int& SetB(int *p){ *p = 20; return *p; } void main(){ int a1 = 阅读全文

posted @ 2016-06-15 09:17 寒魔影 阅读(925) 评论(0) 推荐(0)

导航