C++值传递、引用传递、指针传递以及STL模板堆的使用
来源:互联网 发布:超出数组界限 编辑:程序博客网 时间:2024/06/08 18:58
1、C++中数组作为实际参数传递的三种形式参数方法
#include<iostream>
using namespace std;
void change(int& a,int b){ //通过引用,引用是原变量的别名,变量值返回时会受影响
a=5;
}
void change1(int* a,int b){ //通过指针进行传递,变量值返回时会受影响
*a=0;
}
void change2(int a,int b) { //变量值返回时不会受影响
a=2;
}
int main(){
int c=6,d=4;
change(c,d); //直接传递变量
cout<<c<<endl;
change1(&c,d); //传递变量地址
cout<<c<<endl;
change2(c,d); //传递变量
cout<<c<<endl;
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2、C++中的优先队列,默认是大堆,自定义为小堆,注意:如何重载opertor<函数。
/* 在struct结构中重载operator< 函数
#include<iostream>
#include<string>
#include<queue>
using namespace std;
struct ss{
string name;
double score;
//自定义struct元素类型的operator<重载函数,使得优先队列中,将小元素放在队列的首部
//返回true的排在后面
friend bool operator<( const ss& a, const ss& b){ return a.score> b.score ;
}
};
int main(){
struct ss stu[]={{"suting",120.0},{"xiaowang",123.0},{"xiaoli",110}};
priority_queue<ss> q;
for(int i=0; i< sizeof stu/sizeof stu[0] ; i++)
q.push(stu[i]);
cout<<q.top().name<<endl;
}
*/
- C++值传递、引用传递、指针传递以及STL模板堆的使用
- [C]值传递、指针传递、引用传递
- C++:指针传递、引用传递的区别
- C/C++语言参数传递----值传递、引用传递、指针传递、指针引用传递
- C/C++语言参数传递----值传递、引用传递、指针传递、指针引用传递
- C/C++语言参数传递----值传递、引用传递、指针传递、指针引用传递
- 【c/c++】值传递、指针传递、引用传递
- C或C++中函数的参数传递包括:值传递、指针传递、引用传递
- C或C++中函数的参数传递——值传递、指针传递、引用传递
- C/C++值传递、指针传递和引用传递详解
- c++ 值传递 引用传递 指针传递
- 什么是值传递、引用传递、指针传递
- 值传递、指针传递和引用传递
- 值传递 引用传递 指针传递
- 值传递,引用传递,指针传递
- 值传递,指针传递,引用传递
- C++值传递,指针传递,引用传递
- 值传递、指针传递、引用传递
- windows ddk下载
- windows.h分析
- java 多线程1
- windows.h分析
- 09河南省赛 机器人 广搜
- C++值传递、引用传递、指针传递以及STL模板堆的使用
- linux gcc 编译时头文件和库文件搜索路径
- Android 之 Java 多线程
- C#基础
- 用协议分析工具学习TCP/IP(一)
- Android 的反编译
- javascript正则表达式获取fckeditor的图片地址
- servlet的生命周期以及与其相关的类接口和相关方法
- Android 在一个应用中如何启动另外一个已安装的应用!!!