如何在c++中将此函数重写为指针
How to rewrite this function into a pointer in c++?
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
在我的代码中,我所做的只是在参数和代码体中的变量a
、b
之前添加星号。我的老师说这是错误的,所以现在我不明白了
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
你会称你的原件为:
int one = 1;
int two = 2;
swap(one, two); // references
修改后的功能,如
swap(&one, &two); // pointers
相关文章:
- 在 C++ 中用派生类型重写成员函数
- 重写虚拟函数和继承
- C++调用使用重写函数的父类函数
- 重写打印函数而不是覆盖基类
- 重写函数不打印基类数据
- 将一个小的 C 定义重写为"normal" C++函数
- 重写另一个方法 [C++] 使用的超类回调函数
- 具有派生参数的函数重写
- 在回调中使用函数时,C++未知重写说明符
- 用模板化函数重写虚拟函数
- 没有函数重写的多重继承.为什么模棱两可
- C++ 继承构造函数重写
- 关于C++中的虚拟函数重写
- C++函数重写不起作用
- 如何实现类变量的虚拟函数重写
- 将C++函数重写为C#(将指针传递到数组中的下一个元素)
- 引用可以用于实现函数重写吗
- 用函数重写嵌套的if-else语句
- C++继承函数重写
- 本机C++中的函数重写