注册 登录
编程论坛 C++教室

结构作为返回值。我哪里错了呢?

洪夜馨 发布于 2009-10-14 15:39, 669 次点击
#include "iostream.h"
struct student
{
    int IDnumber;
    char name[15];
    int age;
    char kemu[20];
    float pingjunfen;
};
strudent initial();
void display(student arg);
int main()
{
    display(initial);
    return 0;
}
void display(student arg)
{
    cout<<arg.IDnumber<<arg.name<<arg.age<<arg.kemu<<arg.pingjunfen<<endl;
}
strudent initial();
{
    strundent s1={444444,ca,11,aaaaaa,84.3};
    return s1;
}

根本不明白啊。能告诉我吗?
Compiling...
1.cpp
F:\教育教学\练习\1.cpp(10) : error C2146: syntax error : missing ';' before identifier 'initial'
F:\教育教学\练习\1.cpp(10) : error C2501: 'strudent' : missing storage-class or type specifiers
F:\教育教学\练习\1.cpp(10) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.


[ 本帖最后由 洪夜馨 于 2009-10-14 16:02 编辑 ]
3 回复
#2
newCpp2009-10-14 16:48
程序代码:
#include "iostream.h"
struct student
{
    int IDnumber;
    char name[15];
    int age;
    char kemu[20];
    float pingjunfen;
};
student initial();
void display(student arg);
int main()
{
    student AA=initial();
    display(AA);
    return 0;
}
void display(student arg)
{
    cout<<arg.IDnumber<<arg.name<<arg.age<<arg.kemu<<arg.pingjunfen<<endl;
}
student initial()
{
    student s1={444444,"ca",11,"aaaaaa",84.3};
return s1;
}
都是一些小的细节错误!
比如你在定义结构体函数的时候那个结构体类型名写错了!@
还有一就是initial()在定义功能的时候后面多了一个;号
其实你仔细看看就能够知道哪里错了的!
因为我也不认识英文,这个结果我也是在VC6.0编译器上调试该过来的~
#3
newCpp2009-10-14 16:49
还有一个就是,字符数组在写的时候引号别忘记加上去~~!!
没了引号那肯定是会出错的!
#4
洪夜馨2009-10-14 18:08
程序代码:
#include "iostream.h"
struct student
{
    int IDnumber;
    char name[15];
    int age;
    char kemu[20];
    float pingjunfen;
};
student initial();
void display(student arg);
int main()
{
    display(initial);
    return 0;
}
void display(student arg)
{
    cout<<arg.IDnumber<<arg.name<<arg.age<<arg.kemu<<arg.pingjunfen<<endl;
}
student initial()
{
    student s1={444444,"ca",11,"aaaaaa",84};
    return s1;
}
我按您的说法改好了.可为什么显示
F:\教育教学\练习\1.cpp(14) : error C2664: 'display' : cannot convert parameter 1 from 'struct student (void)' to 'struct student'
        No constructor could take the source type, or constructor overload resolution was ambiguous

呢?
1