-8
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Switch(int& num_1, int& num_2)
{
int temp;
temp = num_1;
num_1 = num_2;
num_2 = temp;
}
int main()
{
cout << Switch(1,2);
}
这是我的代码,它应该将第一个参数与第二个参数切换。我写的这个函数有什么问题?
欢迎来到Stack Overflow。我怀疑你的函数没有返回任何数据,因此你看不到任何输出。什么是预期的输出?该功能的预期结果是什么?它应该做什么? – Twisty
'Switch'没有什么特别的错误。但'main'不会编译。当在这里询问编译器错误时,通常应该复制并粘贴你得到的编译器错误。无论如何,你希望发生什么? – aschepler
文字不能绑定到非const的左值引用,所以没有办法编译这个代码。您不能修改数字文字。 –