就是随便写也出错呀!

gangzichh 2005-12-02 10:31:20
#include<iostream>
#include<string>
using namespace std;
class employee
{
public:
employee(string nam,char s,int a)
protected:
string name;
char sex;
int age;
};

class workerhours:public employee
{
public:
workerhours(string nam,char s,int a,float w):employee(nam,s,a),wage(w){}
void show()
{
cout<<"name"<<name<<endl;
cout<<"age"<<age<<endl;
cout<<"sex"<<sex<<endl;
cout<<"wage"<<wage<<endl;

}
protected:
float wage;

};
int main()
{
workerhour worker1("zhangsan","f",21,8)
worker1.show();
return 0;
}
你也随便写呀
就是要个完整的呀
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zw24127 2005-12-03
  • 打赏
  • 举报
回复
大哥 基类中也要有构造的,主函数中类名要与定义类名一至!!
oyljerry 2005-12-03
  • 打赏
  • 举报
回复
char 对应一个字符就好了 ''
aniude 2005-12-03
  • 打赏
  • 举报
回复
#include<iostream>
#include<string>
using namespace std;
class employee
{
public:
employee(string nam,char s,int a)
{
name = nam;
sex = s;
age = a;
}
protected:
string name;
char sex;
int age;
};

class workerhours:public employee
{
public:
workerhours(string nam,char s,int a,float w):employee(nam,s,a),wage(w){}
void show()
{
cout<<"name"<<name<<endl;
cout<<"age"<<age<<endl;
cout<<"sex"<<sex<<endl;
cout<<"wage"<<wage<<endl;

}
protected:
float wage;

};
int main()
{
workerhours worker1("zhangsan",'f',21,8);
worker1.show();
return 0;
}
VC6.0下通过
Riddick2046 2005-12-03
  • 打赏
  • 举报
回复
employee(string nam,char *s,int a){name=nam;sex=s;age=a;}; 改好.

朋友啊, 你传一个字符串,应该是 char * s 你说是吧.
csucdl 2005-12-02
  • 打赏
  • 举报
回复
class employee
{
public:
employee(string nam,char s,int a):name(name), sex(s), age(a){} //构造函数
protected:
string name;
char sex;
int age;
};

class workerhours:public employee
{
public:
workerhours(string nam,char s,int a,float w):employee(nam,s,a),wage(w){}
void show()
{
cout<<"name"<<name<<endl;
cout<<"age"<<age<<endl;
cout<<"sex"<<sex<<endl;
cout<<"wage"<<wage<<endl;

}
protected:
float wage;

};
int main()
{
workerhour worker1("zhangsan",'f',21,8); //忘了语句结束符号, 字符常量 ''
worker1.show();
return 0;
}
Mr_Yang 2005-12-02
  • 打赏
  • 举报
回复
char s ------------------------------>'f';
char *s------------------------------>"f";
两种该法~
sankt 2005-12-02
  • 打赏
  • 举报
回复
#include<iostream>
#include<string>
using namespace std;

class employee
{
public:
employee(string nam,char s,int a) //======
{
name=nam;
sex=s;
age=a;
}

protected:
string name;
char sex;
int age;
};

class workerhours:public employee
{
public:
workerhours(string nam,char s,int a,float w):employee(nam,s,a),wage(w){}
void show()
{
cout<<"name "<<name<<endl;
cout<<"age "<<age<<endl;
cout<<"sex "<<sex<<endl;
cout<<"wage "<<wage<<endl;

}
protected:
float wage;

};
int main()
{
workerhours worker1("zhangsan",'f',21,8); //============

worker1.show();
system("pause");

return 0;
}

//==========有些小错误
fiftymetre 2005-12-02
  • 打赏
  • 举报
回复
帮你改好了

#include<iostream>
#include<string>
using namespace std;
class employee
{
public:
employee();
employee(string nam,char *s,int a){name=nam;sex=s;age=a;};
protected:
string name;
char *sex;
int age;
};

class workerhours:public employee
{
public:
workerhours(string nam,char *s,int a,float w):employee(nam,s,a),wage(w){}
void show()
{
cout<<"name: "<<name<<endl;
cout<<"age: "<<age<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"wage: "<<wage<<endl;

}
protected:
float wage;

};
int main()
{
workerhours worker1(string("zhangsan"),"f",21,8);
worker1.show();
return 0;
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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