请帮忙改一下程序的错误

davidstack 2009-09-08 03:38:33
#include<iostream>
using namespace std;

struct HJ{
int day;
int month;
int year;
};


void fun1(HJ (&hj)[3][4]);
void fun2(HJ (&hj)[3][4]);
void fun3(HJ (&hj)[3][4]);



int main(){

HJ hj1[3][4];

for(int i=0;i<3;i++)
for(int j=0;j<4;j++)

{ hj1[i][j].day=1;
hj1[i][j].month=i+1;
hj1[i][j].year=j;
}
fun1(hj1);
return 0;

}
void fun1(HJ &hj[3][4]);//error C2234: '<Unknown>' : arrays of references are illegal
{ //error C2447: missing function header (old-style formal list?)
cout<<"hj"<<endl;
cout<<hj[0][1].day<<endl;
}

void fun3(HJ &hj[3][4]);
{
cout<<"hj"<<endl;
cout<<hj[0][1].day<<endl;
}

void fun2(HJ &hj[3][4]);
{
cout<<"hj"<<endl;
cout<<hj[0][1].day<<endl;
}
编译有错误,但是改不了,请高手帮忙。
...全文
117 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
thebestfriend 2009-09-08
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

struct HJ{
int day;
int month;
int year;
};


void fun1(HJ (*hj)[4]);
void fun2(HJ (*hj)[4]);
void fun3(HJ (*hj)[4]);


int main(){

HJ hj1[3][4];

for(int i=0;i<3;i++)
for(int j=0;j<4;j++)

{ hj1[i][j].day=1;
hj1[i][j].month=i+1;
hj1[i][j].year=j;
}
fun1(hj1);
return 0;

}

void fun1(HJ (*hj)[4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day<<endl;
}

void fun3(HJ (*hj)[4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day<<endl;
}

void fun2(HJ (*hj)[4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}
调试通过,建议楼主可以看看多维数组的传递.
roman_v 2009-09-08
  • 打赏
  • 举报
回复
加了code之后引用无效了嘛..
roman_v 2009-09-08
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 oktsl 的回复:]
错误不少啊
我给你改了下 绝对能用了
 #include  <iostream>
using namespace std;

struct HJ{
int day;
int month;
int year;
};


void fun1(HJ (&hj)[3][4]);
void fun2(HJ (&hj)[3][4]);
void fun3(HJ (&hj)[3][4]);


int main(){

HJ hj1[3][4];

for(int i=0;i <3;i++)
for(int j=0;j <4;j++)
{
hj1[i][j].day=1;
hj1[i][j].month=i+1;
hj1[i][j].year=j;
}
fun1(hj1);
system("pause");
return 0;

}
void fun1(HJ (&hj)[3][4])//error C2234: ' <Unknown>' : arrays of references are illegal
{                        //error C2447: missing function header (old-style formal list?)
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}

void fun3(HJ (&hj)[3][4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}

void fun2(HJ (&hj)[3][4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}


[/Quote]

正解!!
oktsl 2009-09-08
  • 打赏
  • 举报
回复
错误不少啊
我给你改了下 绝对能用了
#include <iostream>
using namespace std;

struct HJ{
int day;
int month;
int year;
};


void fun1(HJ (&hj)[3][4]);
void fun2(HJ (&hj)[3][4]);
void fun3(HJ (&hj)[3][4]);


int main(){

HJ hj1[3][4];

for(int i=0;i <3;i++)
for(int j=0;j <4;j++)
{
hj1[i][j].day=1;
hj1[i][j].month=i+1;
hj1[i][j].year=j;
}
fun1(hj1);
system("pause");
return 0;

}
void fun1(HJ (&hj)[3][4])//error C2234: ' <Unknown>' : arrays of references are illegal
{ //error C2447: missing function header (old-style formal list?)
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}

void fun3(HJ (&hj)[3][4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}

void fun2(HJ (&hj)[3][4])
{
cout <<"hj" <<endl;
cout <<hj[0][1].day <<endl;
}
huziwu 2009-09-08
  • 打赏
  • 举报
回复
粗略看了一下,LZ你的函数后面怎么都加了分号(;)
void fun1();
{
...
}
wangjs720 2009-09-08
  • 打赏
  • 举报
回复
数组的引用, 楼上的用法是正确的。
dirdirdir3 2009-09-08
  • 打赏
  • 举报
回复
漏了就是表示参数是一个指向(HP&)的数组......
dirdirdir3 2009-09-08
  • 打赏
  • 举报
回复
void fun1(HJ (&hj)[3][4]);//error C2234: ' <Unknown>' : arrays of references are illegal
{ //error C2447: missing function header (old-style formal list?)
cout < <"hj" < <endl;
cout < <hj[0][1].day < <endl;
}
dirdirdir3 2009-09-08
  • 打赏
  • 举报
回复
要有括号啊,不要漏了,漏了意思就不同了.........
void fun1(HJ (&hj)[3][4]);
davidstack 2009-09-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 youyifang 的回复:]
数组做函数的参数不是把大小直接给进去,要用另外的参数来保存大小
想这样定义看看void fun2(HJ &hj[][], int n, int m);
[/Quote]
不行啊,这样的话错误更多……
youyifang 2009-09-08
  • 打赏
  • 举报
回复
数组做函数的参数不是把大小直接给进去,要用另外的参数来保存大小
想这样定义看看void fun2(HJ &hj[][], int n, int m);

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧