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

第一次使用VC2005,请问错在哪里?

lhj2005 发布于 2007-11-02 13:17, 755 次点击

请各位高手给个指导


//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编辑过]

5 回复
#2
yuyunliuhen2007-11-02 13:27

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

#3
lhj20052007-11-02 13:29

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

提示是:
错误 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编辑过]

#4
lhj20052007-11-02 14:45
有人知道,告诉我下怎么改
#5
lhj20052007-11-02 15:27
我想要的效果是,有实参的时候,输出实际参数
没有实际参数的时候,输出默认值
#6
feixian4062007-11-02 15:33

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

1