C++引用参数调用 ,求救~

来源:百度知道 编辑:UC知道 时间:2024/06/06 00:36:00
#include <iostream.h>
#include <iomanip.h>
void fun1(int a,int b);
void fun2(int& a,int& b);
void fun3(int* a,int* b);

void main()
{
int x=5,y=10;
cout<<x<<setw(10)<<y<<endl;
fun1(x,y);
cout<<x<<setw(10)<<y<<endl;
fun2(x,y);
cout<<x<<setw(10)<<y<<endl;
fun3(&x,&y);
cout<<x<<setw(10)<<y<<endl;
}

void fun1(int a,int b)
{
a=a+b;
b=b*2;
cout<<"fun1"<<a<<setw(10)<<b<<endl;
}

void fun2(int& a,int& b)
{
a=a+b;
b=b*2;
cout<<"fun2"<<a<<setw(10)<<b<<endl;
}

void fun3(int* a,int* b)
{
a=a+b;
b=b*2;
cout<<"fun3"<<*a<<setw(10)<<*b<<endl;
}

编译时候出现以下错误:

#include <iostream.h>
#include <iomanip.h>
void fun1(int a,int b);
void fun2(int& a,int& b);
void fun3(int* a,int* b);

void main()
{
int x=5,y=10;
cout<<x<<setw(10)<<y<<endl;
fun1(x,y);
cout<<x<<setw(10)<<y<<endl;
fun2(x,y);
cout<<x<<setw(10)<<y<<endl;
fun3(&x,&y);
cout<<x<<setw(10)<<y<<endl;
}

void fun1(int a,int b)
{
a=a+b;
b=b*2;
cout<<"fun1 "<<a<<setw(10)<<b<<endl;
}

void fun2(int& a,int& b)
{
a=a+b;
b=b*2;
cout<<"fun2 "<<a<<setw(10)<<b<<endl;
}

void fun3(int* a,int* b)
{
*a=*a+*b;
*b=(*b)*2;
cout<<"fun3 "<<*a<<setw(10)<<*b<<endl;
}

<