上一页 1 ··· 47 48 49 50 51 52 53 54 55 ··· 60 下一页

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 寒魔影 阅读(227) 评论(0) 推荐(0)

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

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

posted @ 2016-06-15 16:22 寒魔影 阅读(227) 评论(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 寒魔影 阅读(311) 评论(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 寒魔影 阅读(883) 评论(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 寒魔影 阅读(343) 评论(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)

2016年6月14日

C++ 引用本质的详解

摘要: //引用本质的理解① #include using namespace std; int GetA(){ int a = 10; return a; } int & GetB(){ int a = 10; printf("a的地址是%x\n", &a); return a; } void main(){ int a1 = 10, a2 = 0... 阅读全文

posted @ 2016-06-14 23:33 寒魔影 阅读(1380) 评论(0) 推荐(0)

2016年6月13日

C++ 引用基础

摘要: //引用 #include using namespace std; struct Student{ char name[30]; int age; }; struct Teacher{ int &at2; int &bt2; }; int GetNum(Student &s2){ s2.age = 19; return s2.age; ... 阅读全文

posted @ 2016-06-13 23:13 寒魔影 阅读(251) 评论(0) 推荐(0)

C语言错误 指针的类型错误

摘要: //指针的类型错误 #include #include #include //用const来限制形参的指向不可以修改,优化代码的安全性 int Getnum(int ** const pin/*in*/){ return 1; } //指针的类型 //指针都是有自己的类型的 例如 int *,int ** //指针的类型本质上是对指针所指向的内存空间一种描述 //一级指针,二级指针只... 阅读全文

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

上一页 1 ··· 47 48 49 50 51 52 53 54 55 ··· 60 下一页

导航