通过引用传递在 C++ 中出错
passing by reference is getting error in c++
#include <iostream>
#include <conio.h>
using namespace std;
int passingByValue(int);
int passingByRef(int&);
int main(){
int rah = 51;
int value = passingByValue(rah);
int har =52;
int ref = passingByRef(har&);
cout<<"passing by value is = "<<value<<endl;
cout<<"passing by ref is = "<<ref<<endl;
system("pause");
}
int passingByValue(int ol){
return ol * ol;
}
int passingByRef(int *x){
return *x=100;
}
它的简单函数按值传递并通过引用传递,但每当我通过引用传递时,我都会收到错误 错误是 11 31 D:\c++ 编程实践\prog21.cpp [错误] "("标记之前的预期主表达式
按引用传递函数定义应如下所示:
int passingByRef(int &x){
return x=100;
}
此外,您应该在不使用运算符地址的情况下调用它:&
int ref = passingByRef(har);
当前用于按引用传递的代码看起来更像是用于按指针传递的代码。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 为重写std::exception的库生成swig接口时出错
- 导入/导出变量时出错
- PrintWindow函数在notepad.exe中出错