| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 669 人关注过本帖
标题:结构作为返回值。我哪里错了呢?
只看楼主 加入收藏
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
结帖率:91.43%
收藏
已结贴  问题点数:1 回复次数:3 
结构作为返回值。我哪里错了呢?
#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 编辑 ]
搜索更多相关主题的帖子: 返回值 结构 
2009-10-14 15:39
newCpp
Rank: 5Rank: 5
来 自:火星
等 级:职业侠客
威 望:3
帖 子:256
专家分:375
注 册:2009-8-17
收藏
得分:0 
程序代码:
#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编译器上调试该过来的~

编程语言视频教程在线播放学习
2009-10-14 16:48
newCpp
Rank: 5Rank: 5
来 自:火星
等 级:职业侠客
威 望:3
帖 子:256
专家分:375
注 册:2009-8-17
收藏
得分:1 
还有一个就是,字符数组在写的时候引号别忘记加上去~~!!
没了引号那肯定是会出错的!

编程语言视频教程在线播放学习
2009-10-14 16:49
洪夜馨
Rank: 1
等 级:新手上路
帖 子:85
专家分:5
注 册:2009-6-12
收藏
得分:0 
程序代码:
#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

呢?
2009-10-14 18:08
快速回复:结构作为返回值。我哪里错了呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014922 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved