| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 755 人关注过本帖
标题:第一次使用VC2005,请问错在哪里?
只看楼主 加入收藏
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
 问题点数:0 回复次数:5 
第一次使用VC2005,请问错在哪里?

请各位高手给个指导


//head.h文件
#include "stdafx.h"
#include "iostream"
#include "string"

using namespace std;

class inputdata{
public:
inputdata(int,string,char,int,int);
~inputdata()
{cout<<"over!"<<endl;
getchar();}
void display();

private:
int id;
string name;
char sex;
int maths;
int chinese;
};



//head.cpp文件
#include "stdafx.h"
#include "head.h"

inputdata::inputdata(int a,string b,char c,int d, int e):id(a),name(b),sex(c),maths(d),chinese(e){}

void inputdata::display()
{
cout<<"name = "<<name<<endl;
cout<<"sum = "<<maths+chinese<<endl;
cout<<"sex = "<<sex<<endl<<endl;
}

//主函数
#include "stdafx.h"
#include "head.h"

int _tmain(int argc, _TCHAR* argv[])
{
inputdata student1;
student1.inputdata(5,"lhj",'f',99,89);
student1.display();
return 0;
}

编译提示:
错误 1 error C2512: 'inputdata' : no appropriate default constructor available archive.cpp 8
错误 2 error C2274: 'function-style cast' : illegal as right side of '.' operator archive.cpp 9

请教下!!! 随便要改进什么吗?

[此贴子已经被作者于2007-11-2 13:43:56编辑过]

搜索更多相关主题的帖子: int include string inputdata 
2007-11-02 13:17
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

代码不完整吧,类的定义呢
按提示啊;
1,没有提供默认可用的构造函数
2,input_data 不是inputdata的成员函数


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-11-02 13:27
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 

前面复制错了,是现在上面的

提示是:
错误 1 error C2512: 'inputdata' : no appropriate default constructor available archive.cpp 8
错误 2 error C2274: 'function-style cast' : illegal as right side of '.' operator archive.cpp 9


没有默认的构造函数???
我赋值了啊!

[此贴子已经被作者于2007-11-2 13:44:36编辑过]

2007-11-02 13:29
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
有人知道,告诉我下怎么改
2007-11-02 14:45
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
我想要的效果是,有实参的时候,输出实际参数
没有实际参数的时候,输出默认值
2007-11-02 15:27
feixian406
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-9-6
收藏
得分:0 

把主函数里这两行:
inputdata student1;
student1.inputdata(5,"lhj",'f',99,89);
合为一行:
inputdata student1(5,"lhj",'f',99,89);

2007-11-02 15:33
快速回复:第一次使用VC2005,请问错在哪里?
数据加载中...
 
   



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

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