(c++)晕啊,七个错, 引用不能引用数组?

/*引用*/
/*输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。
写3个函数...1...输入10个数..2..进行处理...3...输出10个数 */

#include <iostream> //预处理命令
using namespace std;
void deal(int& a[]); //函数声明
int main()
{
int b[10]; //定义变量
int i;

cout << "请输入10个整数:" <<endl; //输入
for (i = 0; i < 10; i++)
cin >> b[i];
cout << endl;

deal (b[10]); //处理,函数调用

cout << "下面是转换结果:" <<endl; //输出结果
for (i = 0; i < 10; i++)
cout << b[i] << " " ;
cout<<endl;

return 0;
}

void deal (int& a[10])
{
int j; //定义变量
int k;
int m;
for (j = 0; j < 9; j++) //最小放最前
if (a[j] > a[j+1])
j = j+1;
k = a[j];
a[j] = a[0];
a[0] = k;

for (j = 0; j < 9; j++) //最大放最后
if (a[j] < a[j+1])
j=j+1;
k = a[j];
a[j] = a[9];
a[9] = k;
}

--------------------Configuration: 003_2 - Win32 Debug--------------------
Compiling...
003_2.cpp
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(7) : error C2234: '<Unknown>' : arrays of references are illegal
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(18) : error C2664: 'deal' : cannot convert parameter 1 from 'int' to 'int *[]'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(29) : error C2234: '<Unknown>' : arrays of references are illegal
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(37) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(39) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(44) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(46) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

003_2.obj - 7 error(s), 0 warning(s)
那引用可以直接引用数组?

引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样。 引用的声明方法:类型标识符 &引用名=目标变量名;
【例1】:int a; int &ra=a; //定义引用ra,它是变量a的引用,即别名
说明:
(1)&在此不是求地址运算,而是起标识作用。
(2)类型标识符是指目标变量的类型。
(3)声明引用时,必须同时对其进行初始化。
(4)引用声明完毕后,相当于目标变量名有两个名称,即该目标原名称和引用名,且不能再把该引用名作为其他变量名的别名。 ra=1; 等价于 a=1;
(5)声明一个引用,不是新定义了一个变量,它只表示该引用名是目标变量名的一个别名,它本身不是一种数据类型,因此引用本身不占存储单元,系统也不给引用分配存储单元。故:对引用求地址,就是对目标变量求地址。&ra与&a相等。
(6 ) 不能建立数组的引用。因为数组是一个由若干个元素所组成的集合,所以无法建立一个数组的别名.
(7)不能建立引用的引用,不能建立指向引用的指针。因为引用不是一种数据类型,所以没有引用的引用,没有引用的指针。 例如: int n; int &&r=n;//错误,编译系统把"int &"看成一体,把"&r"看成一体,即建立了引用的引用,引用的对象应当是某种数据类型的变量 int &*p=n;//错误,编译系统把"int &"看成一体,把" *p "看成一体,即建立了指向引用的指针,指针只能指向某种数据类型的变量
(8)值得一提的是,可以建立指针的引用 例如: int *p; int *&q=p;//正确,编译系统把" int * "看成一体,把"&q"看成一体,即建立指针p的引用,亦即给指针p起别名q。

参考资料:http://zhidao.baidu.com/question/215520247.html

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-10-06
1.deal (b[10]); //处理,函数调用 -------------错误
直接deal(b);就可以了
2.deal函数中两个for有问题
int mark_j = 0;
m = a[0];
for(int j = 1; j < 10; j++)
{
if( m > a[j])
{
m = a[j];
mark_j = j;
}
}
if( mark_j != 0 )
{
k = a[mark_j];
a[mark_j] =a[0];
a[0] = k;
}

m = a[9];
mark_j = 9;
for(j = 0; j < 9; j++)
{
if( m < a[j])
{
m = a[j];
mark_j = j;
}
}
if( mark_j != 9 )
{
k = a[mark_j];
a[mark_j] =a[9];
a[9] = k;
}本回答被提问者采纳
第2个回答  2011-02-18
给你一个可以编译过的,主要是deal函数定义有问题,你可以仔细看看那个部分,传数组的话,你可以使用指针
/*引用*/
/*输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。
写3个函数...1...输入10个数..2..进行处理...3...输出10个数 */

#include <iostream> //预处理命令
using namespace std;
void deal(int *a); //函数声明
int main()
{
int b[10]; //定义变量
int i;

cout << "请输入10个整数:" <<endl; //输入
for (i = 0; i < 10; i++)
cin >> b[i];
cout << endl;

deal (b); //处理,函数调用

cout << "下面是转换结果:" <<endl; //输出结果
for (i = 0; i < 10; i++)
cout << b[i] << " " ;
cout<<endl;

return 0;
}

void deal (int *a)
{
int j; //定义变量
int k;

for (j = 0; j < 9; j++) //最小放最前
if (a[j] > a[j+1])
j = j+1;
k = a[j];
a[j] = a[0];
a[0] = k;

for (j = 0; j < 9; j++) //最大放最后
if (a[j] < a[j+1])
j=j+1;
k = a[j];
a[j] = a[9];
a[9] = k;
}
第3个回答  2011-02-18
简单