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

2016年6月15日

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)

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

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

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

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

2016年6月11日

C++ c++与C语言的区别(三目运算符,const修饰符)

摘要: //区别⑦:三目运算符(C++版本) #include<iostream> using namespace std; //三目运算符 C语言返回变量的值 C++语言是返回变量本身 void main(){ int a = 10; int b = 20; a < b ? a : b = 30; //C 阅读全文

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

C++ c++与C语言的区别(struct类型的加强,函数-变量类型加强,bool类型)

摘要: //区别④:struct类型的加强(C++版本) #include using namespace std; //C++中的struct是一个新类型的定义声明 //c++中结构体的默认访问权限public,和类不同 struct Teacher{ //char name[20]="小米";//报错 error C2536: “Teacher::Teacher::name”: 无法指定数... 阅读全文

posted @ 2016-06-11 10:48 寒魔影 阅读(1280) 评论(0) 推荐(0)

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

导航